Merge just the conflicting changes from dev.typeparams (ast, parser,
types, etc.), excluding io/fs changes.
The rest of the dev.typeparams merge will be done in a later CL, once
the compiler changes have stabilized.
Change-Id: Ic24c5902e4cacc85338ab23b100e5a245a5148bc
Reviewed-on: https://go-review.googlesource.com/c/go/+/286774
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
If the cause is a method with incorrect signature, report the
expected and presented signature.
Updates #41125.
Change-Id: Ibd0fa23547b77df924ec5421cc8e657d41c5a5a6
Reviewed-on: https://go-review.googlesource.com/c/go/+/251717
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Per the latest update to the design draft.
Change-Id: I026b52082e739f6806cd37a0f3e88a546a6f2e90
Reviewed-on: https://go-review.googlesource.com/c/go/+/251139
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
When using unified parameter list syntax, an empty type parameter
list in a type declaration is impossible (it means a slice type).
For symmetry, and because it doesn't make sense to support it,
disallow empty type parameter lists in function declarations.
Accept (parse) them but report a syntax error.
Analogously, disallow empty index/slice/instantiation expressions.
Accept (parse) them but report a syntax error.
Adjust go/types and tests as necessary.
Change-Id: Ifc783245a54d276eb22232a7a74be4d47a7d33fe
Reviewed-on: https://go-review.googlesource.com/c/go/+/250718
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Type and ordinary parameter lists use the same syntax except
for the square brackets or parentheses, respectively.
Change-Id: I6fb93e93bbfc649a2c1ef195d130e0dcee212c79
Reviewed-on: https://go-review.googlesource.com/c/go/+/250717
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Constraint type inference was not enabled for go/go2go and gotype.
Fixes#40859.
Change-Id: Idcab4d0a2eae6f42f938604fb05aabe4ad94c934
Reviewed-on: https://go-review.googlesource.com/c/go/+/249737
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This is a rewrite to drop the type keyword for parameterized functions
and types, and to instead always provide a constraint.
We can revert if we don't like this approach.
Change-Id: If4669fb4e2015067e9f955ff8567ed421be639ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/248880
Reviewed-by: Ian Lance Taylor <iant@golang.org>
We keep an import spec if it uses a local alias. Avoid importing it
again, unless it is required by something else.
Fixes#40318
Change-Id: If90de3bf30412645c9144083372e6b07df3c6a0b
Reviewed-on: https://go-review.googlesource.com/c/go/+/244621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
We can roll back this CL if we go back to parentheses.
Change-Id: Ideb7dbe8e3c4499d76518a5c9b6f7931a7c103a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/243158
Reviewed-by: Ian Lance Taylor <iant@golang.org>
If an embedded field is an instantiated type, we need to instantiate
it when instantiating the whole type, in case the type arguments
themselves need instantiation.
Fixes#39953
Change-Id: I80b57456aa4f8e8b2eff82359066c37a9c2a40f5
Reviewed-on: https://go-review.googlesource.com/c/go/+/240522
Reviewed-by: Ian Lance Taylor <iant@golang.org>
We were relying on calling typeString and treating that as an AST ident,
with special handling for instantiated types, but that fails if there is
an instantiated type within a type literal.
Fixes#39881
Change-Id: I793fe359868d8d73e830aa8dc67cf52de99355a8
Reviewed-on: https://go-review.googlesource.com/c/go/+/240197
Reviewed-by: Ian Lance Taylor <iant@golang.org>
It has no package, so we need to check for Pkg() == nil.
Fixes#39878
Change-Id: I14a47c5098f97ce42dfa8cc875819f244a2b0201
Reviewed-on: https://go-review.googlesource.com/c/go/+/240013
Reviewed-by: Ian Lance Taylor <iant@golang.org>
If an instantiated function from a different package uses a plain
identifier to instantiate a generic type or function, include the
package name in the generated identifier.
Fixes#39834
Change-Id: I4c786bac8972475e180cb41178520439343a36ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/239706
Reviewed-by: Ian Lance Taylor <iant@golang.org>
The go/types package doesn't give us an easy way to get the type,
so just reject it.
Fixes#39743
Change-Id: I5404c10baede0fd2cf67980b06fbebd214a50dff
Reviewed-on: https://go-review.googlesource.com/c/go/+/239382
Reviewed-by: Ian Lance Taylor <iant@golang.org>
types.TypeString defaults to using the package path for references to names.
Provide our own types.Qualifier that uses just the package name,
since that is what the translated code has to use.
Fixes#39744
Change-Id: Icde289b2ed0fdd9b0a9aae6aae4557a8951d25a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/239381
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Ignore struct tags when generating an instantiated names, and when
comparing types for identity.
Fixes#39737
Change-Id: I53e67fa1d09214dafc4088a59eb00e1a6f18ef3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239379
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Move tracking of instantiations from translator to Importer,
so that we can track all instantiations within a package
to avoid duplicates.
Fixes#39749
Change-Id: If6cd5bcdc6e19c2d6481e62a6187ddf7f4fac72a
Reviewed-on: https://go-review.googlesource.com/c/go/+/239337
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Previously we instantiated the underlying type, so we didn't need this.
We stopped doing that to get the same type in the generated code,
but now we need to get the right type arguments, rather than just
leaving the type parameters there.
Fixes#39692
Change-Id: I56ba8ff017c37219e7cb9bb6e07a4beb8c50e9dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/238797
Reviewed-by: Ian Lance Taylor <iant@golang.org>
It shows up when instantiating with types with a package path
containing a slash, as in net/url.Error.
Fixes#39642
Change-Id: Icf40e7bcdf1de7c84f58ebde35ebffadbb071d72
Reviewed-on: https://go-review.googlesource.com/c/go/+/238623
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Avoids crashing when we see a universe scope type in an instantiated type.
Change-Id: Iec3ebee291973180a63cd4cddef7e2f131a30053
Reviewed-on: https://go-review.googlesource.com/c/go/+/238622
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Turn an embedded type parameter into a regular field with the type
parameter as the name and the type argument as the type.
Fixes#39671
Change-Id: I0050499b90feb5085cac4452d53fa0dc6f614c48
Reviewed-on: https://go-review.googlesource.com/c/go/+/238621
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Add an accessor to go/types: HasTypeList for an interface type.
Fixes#39626
Change-Id: I880eabbe6660739cd7febc1df89eaa7f9262c8c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/238360
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Check for comparable embedded via a different embedded interface.
Check for comparable embedded in a defined interface type.
Change-Id: I8c9c576ad31443dcb77b4be71e29ab2284339cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/238357
Reviewed-by: Ian Lance Taylor <iant@golang.org>
types.Identical will report that two instantiated types are different
even if they are instantiated with the same type arguments.
Change our comparison so that we treat them as the same.
This lets us drop fully resolving all types, which is good because
that wasn't correct anyhow.
Change-Id: Ibcf2dc08896ecacb11ca302627e5d0c6f0722da7
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/769080
Reviewed-by: Ian Lance Taylor <iant@google.com>
These are from the latest version of the design draft.
There are still a couple of FromStrings test cases that don't yet work.
Change-Id: I057875820d8250012c06faeabda4637f0585b6f8
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/763941
Reviewed-by: Ian Lance Taylor <iant@google.com>