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>
Specifically, this change accepts now:
1) Type parameters in type and function declarations, such as:
type B(type T) interface {
m(T) T
}
func f(type T B) (list []T) T
2) Type instantiations:
type T B(int)
3) Embedded instantiated types, with necessary extra parentheses:
type T struct {
(B(int)) // ()'s to distinguish from field B of type (int)
}
type T interface {
(B(int)) // ()'s to distinguish from method B with int argument
}
The compiler simply ignores the new constructs.
Change-Id: Iecb8354d3846d7a5786cbe7d92870d8a2d578133
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/736539
Reviewed-by: Robert Griesemer <gri@google.com>
If a type or type parameter does not satisfy a contract because the
type or type constraint is not found in the list of type constraints,
change
T does not satisfy C(T) (T type constraint int not found in interface{type ...})
to
T does not satisfy C(T) (T type constraint int not found in [type ...])
Also, before this change, if the contract had any required methods,
those were also listed; now we just list the type constraints.
If a defined type does not satisfy a contract because the underlying
type is not found in the list of type constraints, change
MyUint does not satisfy C(T) (MyUint not found in interface{type ...})
to
MyUint does not satisfy C(T) (uint not found in [type ...])
That is, when describing the type that is not found, use the underlying type,
not the defined type.
Change-Id: I345836c44921e2e13e7f02041839b5eb4df75c45
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718718
Reviewed-by: Robert Griesemer <gri@google.com>
If a type parameter that has no type constraints is trying to satisfy
a contract that does have type constraints, change
T does not satisfy C(T) (missing type int)
to
T does not satisfy C(T) (T has no type constraints)
If a type parameter that has type constraints is trying to satisfy a
contract that has type constraints, but the parameter has type
constraints that the contract does not permit, change
T does not satisfy C(T) (missing type int)
to
T does not satisfy C(T) (T type constraint int not found in interface{type ...}
Change-Id: I3bd4f59b0544b382399d9b9d891a509ce62f56c3
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/718426
Reviewed-by: Robert Griesemer <gri@google.com>
Otherwise we don't know the type of an instantiated type in an
instantiated function.
Change-Id: If7eb75dd920a3c9fc1b6992addcd3b91b6d425a9
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go2-dev/+/715718
Reviewed-by: Ian Lance Taylor <iant@google.com>