Commit Graph

44452 Commits

Author SHA1 Message Date
Robert Griesemer 236ad5a280 [dev.go2go] go/types: fix broken test case
While at it, simplified test case a bit.

Fixes #39935.
Updates #39754.

Change-Id: Ia3b51f23807d25e62113757c51a660c7e3a9b381
Reviewed-on: https://go-review.googlesource.com/c/go/+/240478
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-30 03:51:21 +00:00
tdakkota 71c7be55eb [dev.go2go] go/types: fix type check skipping for constraints when th…
…ere’s more than one generic constraint.

Check of first constraint was breaking the loop, so other constraints was skipped

Fixes #39754.

Change-Id: I48caa380472371a438c2d2029d1383d03dbf22df
GitHub-Last-Rev: bf418db782
GitHub-Pull-Request: golang/go#39902
Reviewed-on: https://go-review.googlesource.com/c/go/+/240339
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-29 16:07:10 +00:00
Ian Lance Taylor 10ea225e28 [dev.go2go] go/go2go: translate types to AST
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>
2020-06-26 22:32:53 +00:00
Ian Lance Taylor 93014c51d1 [dev.go2go] go/go2go: avoid crashing on predeclared error type
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>
2020-06-26 18:43:49 +00:00
Ian Lance Taylor 1b08acee45 [dev.go2go] go/go2go: don't add importable name to test file
No test case because we will don't have a general test harness.

Fixes #39851

Change-Id: If7b1262404f390eba80d53c2c1d40724252a5833
Reviewed-on: https://go-review.googlesource.com/c/go/+/240004
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-25 23:22:18 +00:00
Ian Lance Taylor 4dfbf5ab9c [dev.go2go] go/go2go: add package qualifier when needed
Fixes #39842

Change-Id: I5046f1bdd7dbc6d1e17cf3835826933aaadf1581
Reviewed-on: https://go-review.googlesource.com/c/go/+/239711
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-25 02:57:14 +00:00
Ian Lance Taylor a9f31a8c68 [dev.go2go] cmd/go2go: doc: instantiations can't refer to unexported names
For #39840

Change-Id: Ifc2a95fbd50cbf785251d05042e554872e1e79cc
Reviewed-on: https://go-review.googlesource.com/c/go/+/239709
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 23:56:06 +00:00
Ian Lance Taylor acd7923802 [dev.go2go] go/go2go: add IDs for test files
No test because the test harness doesn't support test packages.
(But probably we'll need a better test harness.)

Fixes #39839

Change-Id: I4532b1443dbdd081552ffb78477cbe5039183416
Reviewed-on: https://go-review.googlesource.com/c/go/+/239708
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 23:41:00 +00:00
Ian Lance Taylor 2dce748bd8 [dev.go2go] go/go2go: if we have an import path, pass it to go/types
No test because it doesn't really fit into the current test harness.

FIxes #39797

Change-Id: I410217a0e6b3af6808a111d0edbafaa3047b12f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/239707
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 22:35:01 +00:00
Ian Lance Taylor f04e0ee126 [dev.go2go] go/go2go: include package in instantation of ident
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>
2020-06-24 22:15:29 +00:00
Ian Lance Taylor 5b16464101 [dev.go2go] test: keep translated .go2 files if -k
Change-Id: I8f696c201c00d422b176a65ae72e384cc11e1efb
Reviewed-on: https://go-review.googlesource.com/c/go/+/239704
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:34:54 +00:00
Ian Lance Taylor af16dac1b0 [dev.go2go] go/go2go: don't import both "./a" and "a"
For #39797

Change-Id: I4063a0138062ce8dc1f35cc7fef7c6773c939362
Reviewed-on: https://go-review.googlesource.com/c/go/+/239703
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:33:55 +00:00
Ian Lance Taylor fa201df81e [dev.go2go] go/go2go: update name of embedded pointer to instantiation
Fixes #39774

Change-Id: Icb2948ae19e06a3766e7edb01ef40de50e7aca7e
Reviewed-on: https://go-review.googlesource.com/c/go/+/239702
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-24 21:01:03 +00:00
DeedleFake 2dc2987ac8 cmd/go2go: standardize help flag with other tools
A very small change because the `--help` flag printing nothing was bugging me.

Change-Id: I221c657ba055e94db7a574c8e8fd044bb135f8b1
GitHub-Last-Rev: 8781a1a29f
GitHub-Pull-Request: golang/go#39788
Reviewed-on: https://go-review.googlesource.com/c/go/+/239537
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-23 23:41:16 +00:00
Ian Lance Taylor e6e8041d02 [dev.go2go] go/go2go: resolve type alias of parameterized type
Fixes #39792

Change-Id: I9eab19a4f516be5a71e71f04b91c4e46b189fba9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239598
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-23 23:35:25 +00:00
Robert Griesemer 2faeebf4e5 [dev.go2go] go/types: permit alias to generic type
Fixes #39768.

Change-Id: I68c8fbec5adc50e448dabe90b212ef147a384a06
Reviewed-on: https://go-review.googlesource.com/c/go/+/239387
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-23 04:54:48 +00:00
Robert Griesemer 6ca930a00a [dev.go2go] go/types: add internal TODO for future simplification
Change-Id: I8e4e8eebf8c64962ccf5f0e225dd007f691c373a
Reviewed-on: https://go-review.googlesource.com/c/go/+/239384
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-22 23:46:33 +00:00
Ian Lance Taylor dfb538cec8 [dev.go2go] go/go2go: don't permit underscore as type argument
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>
2020-06-22 23:30:28 +00:00
Ian Lance Taylor 404a12f056 [dev.go2go] go/go2go: use package name, not package path
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>
2020-06-22 23:05:26 +00:00
Ian Lance Taylor a367b7d270 [dev.go2go] go/go2go: check for instantiation with locally defined type
Fixes #39738

Change-Id: I1a3536484a982ec713019572ff7b3c0c36af9784
Reviewed-on: https://go-review.googlesource.com/c/go/+/239380
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 22:19:20 +00:00
Ian Lance Taylor 9b13ca00f8 [dev.go2go] go/go2go: ignore struct tags
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>
2020-06-22 22:07:26 +00:00
Robert Griesemer da7932368b [dev.go2go] go/types: implement a few more predicates for type list sums
Also: Don't convert an untyped nil to a type parameter when
checking if an untyped value (nil) can be coverted to a target
type.

Fixes #39755.

Change-Id: Ib2645759dc659b9c80c2d0a457180eb9616c7cb9
Reviewed-on: https://go-review.googlesource.com/c/go/+/239338
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-22 19:06:44 +00:00
Ian Lance Taylor e643c9792f [dev.go2go] go/go2go: avoid multiple identical instantiations
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>
2020-06-22 18:38:41 +00:00
Ian Lance Taylor 6500ed4790 [dev.go2go] go/go2go: instantiate local type specs
Fixes #39741

Change-Id: I75e3b98afa5184b87d4a7bbf360761e5cc6c6217
Reviewed-on: https://go-review.googlesource.com/c/go/+/239297
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-22 17:38:38 +00:00
Robert Griesemer 0a030888da [dev.go2go] go/types: use the underlying type of type list entries
Type lists can contain defined types, make sure we use their
underlying types when computing operational types.

Change-Id: I8b6b11302f6b28977916e495f1486cc7b352e859
Reviewed-on: https://go-review.googlesource.com/c/go/+/239163
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 04:46:40 +00:00
Robert Griesemer c0c872e8b0 [dev.go2go] go/types: the underlying type of a type parameter is itself
No need to call Under() when we know that we have a type parameter.

While at it: Turn off debug mode.

Change-Id: Ia0b39d88191c8e5ac580e7e84a512061911c40cf
Reviewed-on: https://go-review.googlesource.com/c/go/+/239162
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 03:57:21 +00:00
Robert Griesemer cbdb93d5a7 [dev.go2go] go/types: a type constraint must be an interface
In particular, it cannot be a type parameter
with an operational type that is an interface.

Fixes #39723.

Change-Id: Ia6b65eaecd472dd71b1c9f7631ce1872f06e5a6d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239161
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 03:49:15 +00:00
Ian Lance Taylor 815b29d859 [dev.go2go] go/go2go: get package name from package, not import path
No test because the test framework doesn't easily support
package paths containing a dot.

Fixes #39722

Change-Id: If43dc768b28f521d10bd2ef4288aa789aa4bee01
Reviewed-on: https://go-review.googlesource.com/c/go/+/239160
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:45:10 +00:00
Robert Griesemer 7473c4383e [dev.go2go] go/types: check for duplicate types after interfaces were completed
Fixes #39711.

Change-Id: Id0efb854a42bd88a66be8165fa3444e33d1c8f8d
Reviewed-on: https://go-review.googlesource.com/c/go/+/239158
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-20 00:41:07 +00:00
Ian Lance Taylor ccaf3f5560 [dev.go2go] go/go2go: don't crash on an unnamed receiver
Fixes #39707

Change-Id: I20e5fe2990ceda5429f1a22edf48494d2c6496a2
Reviewed-on: https://go-review.googlesource.com/c/go/+/239159
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:36:20 +00:00
Ian Lance Taylor cab5f803e8 [dev.go2go] go/go2go: don't drop type arguments in instantiateType
It's not correct to do it here, as we aren't instantiating this
particular type.

Also had a loop check to avoid endless instantiating a recursive type.

Fixes #39688

Change-Id: Ief4c57bb5cea3013501e33ab5bc82a29707af5be
Reviewed-on: https://go-review.googlesource.com/c/go/+/239137
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-20 00:01:12 +00:00
Robert Griesemer 6cf535a27b [dev.go2go] go/types: avoid endless recursion when computing operational types
The operational type for a type parameter T constrained by
interface { type T } is the top type, not itself. The latter
can lead to infinite recursions.

Fix suggested by @tdakkota.

Fixes #39680.

Change-Id: I8a6a6c503f09294b9276965f1d9e05c5d22ec912
Reviewed-on: https://go-review.googlesource.com/c/go/+/238863
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-19 04:37:09 +00:00
Robert Griesemer b302b5f775 [dev.go2go] go/types: don't panic if an embedded type is not an interface
Fixes #39693.

Change-Id: I7f2a4dd95edac3365a9b41b66afcd0015b5b836c
Reviewed-on: https://go-review.googlesource.com/c/go/+/238858
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-19 00:09:12 +00:00
Ian Lance Taylor 657803033f [dev.go2go] go/go2go: handle fields promoted through embedded type parameter
Fixes #39678

Change-Id: Ib74d15795ab85ad0b1e58096302a9a88810242c5
Reviewed-on: https://go-review.googlesource.com/c/go/+/238857
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 23:28:46 +00:00
Ian Lance Taylor 20dbf4d49d [dev.go2go] go/go2go: add imports for packages referenced by inferred types
Fixes #39625

Change-Id: Iebae2afbb42092e14c91c52d2046bc287d423844
Reviewed-on: https://go-review.googlesource.com/c/go/+/238817
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 22:00:57 +00:00
Ian Lance Taylor 4af4810e15 [dev.go2go] go/go2go: add type arguments to type instantiation
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>
2020-06-18 21:36:57 +00:00
Ian Lance Taylor 7a16d6c119 [dev.go2go] go/go2go: don't crash on functions/methods with no body
Fixes #39672

Change-Id: Ia9fa4e7d5090200d7c2b4f654ac7ee42d7d79732
Reviewed-on: https://go-review.googlesource.com/c/go/+/238761
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-18 20:51:39 +00:00
Robert Griesemer 5e754162cd [dev.go2go] go/types: fix unification issue when looking up generic methods
If enabled in types.Config, the type checker can handle generic
methods (methods that have their own type parameter list).
This CL fixes an issue with method lookup (missing method test)
that caused some assignments to fail.

Note that this does not affect the go2go tool - we don't have any
plans to support such generic methods. Type-checking them is
fairly straight-forward. Translating them into code is not.

Change-Id: I8b8a6b814417277c728732bd5a9421c99440a47a
Reviewed-on: https://go-review.googlesource.com/c/go/+/238627
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-18 05:58:40 +00:00
Robert Griesemer 2c4c09e4ff [dev.go2go] go/types: don't crash when receiver type doesn't declare type parameters
Fixes #39664.

Change-Id: I0cf585f0c704bdaa163a7ebc9e7c82a734fcd5e9
Reviewed-on: https://go-review.googlesource.com/c/go/+/238625
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-18 00:39:33 +00:00
Ian Lance Taylor 57cec2f259 [dev.go2go] go/go2go: accept slash in an instantiated type name
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>
2020-06-17 23:45:00 +00:00
Ian Lance Taylor e531e11b9a [dev.go2go] go/go2go: return quickly from typeWithoutArgs if no args
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>
2020-06-17 23:34:10 +00:00
Ian Lance Taylor 9840dbbef8 [dev.go2go] go/go2go: instantiate embedded type parameters
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>
2020-06-17 23:21:31 +00:00
Ahmed W 3f40f78cab README.go2go: add a note about GO2PATH
Adds a little note about `GO2PATH` and that it is required for the `go2go` tool.

Updates #39617

Change-Id: I9e3cea16a7d7539555180dc065957d6a56f390b9
GitHub-Last-Rev: 2aa6815df7
GitHub-Pull-Request: golang/go#39657
Reviewed-on: https://go-review.googlesource.com/c/go/+/238498
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:48:43 +00:00
Ian Lance Taylor 4287a49936 [dev.go2go] cmd/go2go: document that function-local parameterized types don't work
For #39643

Change-Id: Ic3d3e4a4bd46c62705d3ce3473e3e06e1380d834
Reviewed-on: https://go-review.googlesource.com/c/go/+/238620
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:05:55 +00:00
Ian Lance Taylor 143b944192 [dev.go2go] go/go2go: error, not panic, for local parameterized type
Fixes #39643

Change-Id: I45aaaf8818d4d383d1514891b5cc9bc68926ad97
Reviewed-on: https://go-review.googlesource.com/c/go/+/238619
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 22:03:14 +00:00
Ian Lance Taylor e0d5d9f770 [dev.go2go] go/go2go: make uses of typeInstantiations consistent
Fixes #39653

Change-Id: I98fd1bd4f0deccb5b4c2ed0d67d508c7f0117839
Reviewed-on: https://go-review.googlesource.com/c/go/+/238618
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 21:53:37 +00:00
Ian Lance Taylor 3a25e98917 [dev.go2go] go/go2go: parenthesize type strings
Fixes #39662

Change-Id: Id176ec00474d66a24e95f2db092f3b4245a93cfb
Reviewed-on: https://go-review.googlesource.com/c/go/+/238557
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-06-17 19:42:47 +00:00
Ian Lance Taylor 5f01333bf1 [dev.go2go] go/go2go: check for embedded interface with type list
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>
2020-06-17 04:20:54 +00:00
Robert Griesemer 0b89d8b52a [dev.go2go] go/types: use correct predicate when checking binary addition
See also https://team-review.git.corp.google.com/c/golang/go2-dev/+/759562
for the analogous problem for another predicate.

Fixes #39623.

Change-Id: I39efcb07c337691eb202de166e2cb8d6b5d5ee18
Reviewed-on: https://go-review.googlesource.com/c/go/+/238359
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-06-17 03:59:45 +00:00
Ian Lance Taylor 1bcef8724f [dev.go2go] go/go2go: catch more embedded comparable cases
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>
2020-06-17 03:29:48 +00:00