Commit Graph

44539 Commits

Author SHA1 Message Date
Robert Griesemer e6a1350191 [dev.go2go] cmd/compile/internal/syntax: restore errors for embedded parenthesized fields
When we used ()'s for type parameters, we needed to relax the rules for
embedded struct fields and interface methods: parenthesized embedded
fields and methods were necessary to disambiguate from other constructs.
Now that we use []'s, we can go back to the existing Go rules.

Minor cleanups.

Change-Id: I45399e5b5592c76654a5d504f8bb8b23fff53b85
Reviewed-on: https://go-review.googlesource.com/c/go/+/253997
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-10 18:36:09 +00:00
Robert Griesemer c3f85a2312 [dev.go2go] cmd/compile/internal/syntax: use unified parameter syntax
- type and ordinary parameter list follow the same syntax
- type parameters are enclosed in [], ordinary parameters use ()
- type parameter lists cannot be empty
- all type parameters must be named

Adjusted parser to follow new syntax. Lots of related cleanups.
Adjusted testdata/go2/x.go2 tests and removed the xB.go2 tests.
Preliminary adjustments to types2 package to make tests pass.

Change-Id: Ic4e6597180b97f06345f60cafa9bfc7c642a26ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/253040
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-10 04:49:13 +00:00
Ian Lance Taylor e6b857770a [dev.go2go] go/go2go: handle inferred arguments for index expressions
Fixes golang/go#41216

Change-Id: Iff109f0a7f047742c5f90d64db201712c04f3259
Reviewed-on: https://go-review.googlesource.com/c/go/+/253818
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-09-09 21:19:10 +00:00
Robert Griesemer 573d94888f [dev.go2go] go/types: don't crash when a generic function is instantiated with a value
Change-Id: I9fe898c57590e9d80545543bca87676e16c6b728
Reviewed-on: https://go-review.googlesource.com/c/go/+/253379
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-07 21:23:04 +00:00
Robert Griesemer a2c342556d [dev.go2go] go/types: record constraint type inference when some type params are provided
The existing code didn't record the results of constraint type inference
when it was applied to a partial list of (provided) type parameters.

Changed Info.Inferred map to accept *ast.CallExpr and *ast.IndexExpr
as keys ("call" may be f(x) or f[T]).

Updates #41216.

Change-Id: I5da7467d01643bf74fb78f6c6728209cbd4006c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/253258
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-07 19:09:58 +00:00
Robert Griesemer 9ff2aa4272 [dev.go2go] cmd/gofmt, go/format: set []-mode for type parameters in a few more places
Now that we have mostly settled on the type parameter list syntax we should
probably remove the various modes of parsing and printing. For now just set
the UseBrackets flag explicitly when printing.

Updates #41195.

Change-Id: I56b06b4f930908579a38a140e8221618c8e2fa17
Reviewed-on: https://go-review.googlesource.com/c/go/+/252879
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-09-02 23:45:03 +00:00
Robert Griesemer 8ea0120a21 [dev.go2go] go/types: interfaces with type lists are only allowed as constraints
Check that such constraint interfaces don't appear in:
- composite types
- type and function instantiations
- assertions
- type switches

Streamlined respective error messages. Added lots of tests.

Fixes #41124.

Change-Id: Ie04a95ab056b40561484f04ed6e843ca371e1d41
Reviewed-on: https://go-review.googlesource.com/c/go/+/251718
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-31 05:23:21 +00:00
Robert Griesemer c4914f19b5 [dev.go2go] go/types: improve error when a type argument doesn't satisfy constraint
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>
2020-08-31 00:10:51 +00:00
Robert Griesemer ea8318cad7 [dev.go2go] go/parser, go/types: type parameters must always be named
Change-Id: Ia78ec8ebc7bc7432c3ca3c75dbca3ffedc6ab388
Reviewed-on: https://go-review.googlesource.com/c/go/+/251561
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-29 01:02:37 +00:00
Robert Griesemer 4d89d2a7e3 [dev.go2go] go/parser: adjust error message for mixed parameter lists
Error doesn't just apply to ordinary function parameters anymore;
it could be a (type or function) type parameter list.

Change-Id: Ied75d363917079b265140eb1f1a291d98e019229
Reviewed-on: https://go-review.googlesource.com/c/go/+/251558
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-28 22:45:43 +00:00
Robert Griesemer 4461513296 [dev.go2go] go/types: add missing instantiation checks for function type arguments
Fixes #40684.

Change-Id: If642edbf321973729a8d5b36b4bf61e3fae7ee3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/251557
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-28 22:45:41 +00:00
Robert Griesemer 93e810a5f5 [dev.go2go] go/types: gotype cmd to use new unified type parameter syntax
Change-Id: I76b0d0312e9f7e262139e3b7e4fb8c22989fbca9
Reviewed-on: https://go-review.googlesource.com/c/go/+/251443
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-28 22:12:57 +00:00
Ian Lance Taylor 36bab40fc1 [dev.go2go] cmd/gofmt: pass UnifiedParamLists to parser
Fixes #41079

Change-Id: I781c5c681c66712ed2ac0112dd44fa8793845978
Reviewed-on: https://go-review.googlesource.com/c/go/+/251278
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-08-28 02:28:04 +00:00
Robert Griesemer 5e60d1e8c7 [dev.go2go] go/types: predeclared "any" is only visible as constraint in a type parameter list
Per the restriction in the current design draft.

Change-Id: Ic6ff597849335fa23de22529999d20aacfc205b0
Reviewed-on: https://go-review.googlesource.com/c/go/+/251140
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 23:37:57 +00:00
Robert Griesemer dd1af75a70 [dev.go2go] go/types: disable implicit instantiation of single type parameter constraints
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>
2020-08-27 23:37:55 +00:00
Robert Griesemer af1adc5d8c [dev.go2go] go/parser, go/types: make type parameters a syntax error for type aliases
Accept parameterized aliases for robustness but complain.

Change-Id: I86ad945af253b6c483fca0ac331245730fb22a66
Reviewed-on: https://go-review.googlesource.com/c/go/+/251138
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 20:00:05 +00:00
Robert Griesemer 21bc157bc5 [dev.go2go] go/parser: disallow empty type parameter lists and instantiations
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>
2020-08-27 19:10:21 +00:00
Robert Griesemer 3314879ed2 [dev.go2go] go/printer: don't write "type" keyword in type parameter lists if brackets are used
When the printer mode UseBrackets is set, use the new unified parameter
list syntax: use []'s for type parameters without the "type" keyword.
This will also change gofmt behavior accordingly.

Fixes #41053.

Change-Id: Ibaf490ea9ed178684bea34da5b57afa823a6829f
Reviewed-on: https://go-review.googlesource.com/c/go/+/250998
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-27 05:16:25 +00:00
Robert Griesemer 27c9d6ef7c [dev.go2go] cmd/go2go: switch to unified parameter syntax
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>
2020-08-26 16:50:50 +00:00
Robert Griesemer 1964d56295 [dev.go2go] go/types: adjust all tests to use latest syntax
- use square brackets for type parameters
- otherwise, use same syntax as for ordinary parameters:
  all type parameters must have a constraint, can be "any"
- remove (rename) all *B.go2 tests in favor of adjusted *.go2 tests
- remove tests related to pointer notation for type parameters
  (we are going to use constraint type inference instead)
- adjust type string computation accordingly
- minor related adjustments

This change can be reverted if we don't like it.

Change-Id: Ie1034e0996df8f5ca6fbdf9ecaa3c93fcfd7106d
Reviewed-on: https://go-review.googlesource.com/c/go/+/249741
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
2020-08-26 01:59:01 +00:00
Robert Griesemer 7d90fb0025 [dev.go2go] go/parser: add mode for unified type and ordinary parameter list syntax
If UnifiedParamLists is set, type parameter must follow the syntax of ordinary
parameter lists except that they use square brackets rather than parentheses.

Change-Id: Ia17753eab2ab07e9ef62715a7b97d641f7d08cca
Reviewed-on: https://go-review.googlesource.com/c/go/+/249740
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-26 01:57:29 +00:00
Robert Griesemer 12c2128b9e [dev.go2go] go/go2go, go/types: enable constraint type inference
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>
2020-08-21 00:12:31 +00:00
Ian Lance Taylor ec50ad4981 [dev.go2go] cmd/go2go: in testdata, drop type keyword, always provide constraint
This is a rewrite of the tests 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: I9cd097b8db2aa3c84a40a7aeaa10246ab3b990dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/248897
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-08-17 17:54:56 +00:00
Ian Lance Taylor bc00f5ba9f [dev.go2go] test: drop type keyword, always provide constraint
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>
2020-08-17 17:54:48 +00:00
Robert Griesemer af48c2e84b [dev.go2go] go/types: use actual (not underlying) types of type list elements for interface satisfaction
This is a rule change in an attempt to streamline interface satisfaction:
If a (constraint) interface contains a type list, a type argument's type
or underlying type must be included in the type list (and the interface's
methods must be present, of course). Until now, a type argument's under-
lying type had to be one of the underlying types of the types in the type
list.

The effect is subtle: Because an underlying type is never a defined type,
if a type list contains defined types, only those defined types satisfy
the interface. If we want the interface to be more flexible, we can in-
clude non-defined types in its type list. In the common case, type lists
simply contain predeclared types (whose underlying types are themselves),
so this doesn't matter. An observable difference appears only for code
that currently uses defined types in constraint type lists: such code
becomes slightly more restrictive.

The primary benefit of this change is that it opens the door for general
(non-constraint) use of interfaces with type lists: Using the same rules
as for constraint satisfaction, a value may be assigned to a variable of
such an interface if it or its underlying type of the value is included
int the interface's type list. If the type list contains only defined types,
the respective interface acts like a sum type: it can only contain values
of those types (and nil).

This CL only changes the rules for constraints. It does not permit
interfaces with type lists for general (non-constraint) use for now.

Change-Id: I3f25b9d883dd865a74c583efee4be2e22258d493
Reviewed-on: https://go-review.googlesource.com/c/go/+/248265
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-14 23:21:42 +00:00
Robert Griesemer 722af87f62 [dev.go2go] go/types: determine if type declaration is generic based on use of type parameter
This change makes it possible to declare a generic type with exactly
one type parameter and no constraints without any special syntactic
augmentation: Instead, the parser determines whether a declaration
of the form

	type T[P] type_literal

is an array or generic declaration based on how the type parameter
P is used in type_literal. If P appears only in array lengths (if
at all) in type_literal, T is an array type. Otherwise it is a
generic type.

Change-Id: I6c1d62d61d04f322d73ee16840e0f3ffe299f4c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/248438
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-14 05:30:01 +00:00
Robert Griesemer c3a77cc2d3 [dev.go2go] go/types: predeclare type any interface{} (experiment)
For fine-tuning the type parameter list notation. If we
proceed with square brackets rather than parentheses, we
don't need the "type" keyword in type parameter lists in
many cases. However, generic type declarations with one
type parameter and no constraint must somehow disambiguate
from array type declarations:

	type T[P] E

could be a generic type, or an array type declaration

	type T [P]E

There's a variety of choices for disambiguation, such as:

	type T[type P] E         // what we do now
	type T[P interface{}] E  // currently permitted
	type T[P any] E          // permitted with this CL
	type T[P,] E             // currently permitted

If we abandon the "type" keyword (currently optional), we
need an alternative. Writing the constraint seems nicer than
the comma option (in Go, all parameter lists permit a trailing
comma, but an array length specification doesn't allow it).
If we write the constraint, which is often the empty interface,
being able to write "any" would be more convenient.

In the past we have refused to add "any" to the language. There
may be many more situations where we need to specify an empty
constraint (any) so perhaps adding "any" is now justified. It
would also streamline a lot of existing code such as

	Printf(format string, args... any)

Change-Id: I366342ba8d981d344c96b1ceb60f61d963e9175a
Reviewed-on: https://go-review.googlesource.com/c/go/+/248263
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-14 05:13:41 +00:00
Robert Griesemer 2b748f02a0 [dev.go2go] cmd/compile/internal/types2: fix instantiation crash for generic type parameters
Port of go/types CL https://golang.org/cl/247498.

Updates #40038.

Change-Id: Iab002132627b689e0113c087b3f4d38c6356c3a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/248058
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-12 00:03:11 +00:00
Robert Griesemer fc29b9010e [dev.go2go] cmd/compile/internal/types2: add special case report for generic map key type
Port of go/types CL https://golang.org/cl/247258. (The typeparamsB.go2
version of typeparams.go2 doesn't exist yet for types2.)

Updates #40551.

Change-Id: If2b329372bd4d160b4def8b66cc87f25ed4823fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/248057
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-12 00:03:09 +00:00
tdakkota cb2cbbcda2 [dev.go2go] go/types: fix instantiation crash for generic type parame…
…ters

Fixes #40038.

Change-Id: I5b095d01fd1e3703561c179c34ddc3b43d7510f6
GitHub-Last-Rev: 3e5067a780
GitHub-Pull-Request: golang/go#40644
Reviewed-on: https://go-review.googlesource.com/c/go/+/247498
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-11 16:59:21 +00:00
tdakkota 6d33075156 [dev.go2go] go/types: add special case report for generic map key type
Fixes #40551.

Change-Id: Ifc10dbdcdbee6af5bdbfc36ec78e1a4361672acc
GitHub-Last-Rev: 8d373dee63
GitHub-Pull-Request: golang/go#40628
Reviewed-on: https://go-review.googlesource.com/c/go/+/247258
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-11 16:58:03 +00:00
Robert Griesemer ead7e9b351 [dev.go2go] cmd/compile/internal/syntax: add more parser tests
Updated existing tests to more closely match the go/types
tests; added *B.go2 versions for some tests, using [] for
type parameters.

Change-Id: Ie7cfd9f5515f541d9422a2b2ab8a5d3e02d0499a
Reviewed-on: https://go-review.googlesource.com/c/go/+/246261
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 05:14:38 +00:00
Robert Griesemer d8b0f3b91f [dev.go2go] go/parser: p.T(P) is a valid instantiated parameter type (fix bug)
The existing code didn't accept an instantiated imported (qualified) type
as type for a regular function parameter.

Also: Simplified logic around use of typeContext flag when []'s
      are used for type parameters.

Change-Id: Ic6c60e943344a976f5b8546c8a378ebd32a82d90
Reviewed-on: https://go-review.googlesource.com/c/go/+/246260
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 01:12:24 +00:00
Robert Griesemer 417abfbaf1 [dev.go2go] cmd/compile/internal/syntax: accept [] for type parameter lists
Still missing:
- embedded []-instantiated types in interfaces
- *B.go2 tests which exist for go/types

Change-Id: I3dd115fcd67f725144062c90550a91fcded1cbe2
Reviewed-on: https://go-review.googlesource.com/c/go/+/246259
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 01:12:23 +00:00
Robert Griesemer c77c3236b1 [dev.go2go] cmd/compile/internal/types2: remove most token.Token dependencies
The remaining uses of token.Token are needed for the go/constant API.

Change-Id: I5dc8be1fae16217433da1acb5606fd1d7b8eea54
Reviewed-on: https://go-review.googlesource.com/c/go/+/246257
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-08-01 01:12:22 +00:00
Robert Griesemer 569c893c93 [dev.go2go] types2: update to include the latest go/types changes
This brings types2 (the syntax-based type-checker) up-to-date
with the latest version of the prototype go/types version. It
does not yet include the *B.go2 tests (using square brackets)
or the relevant syntax parser changes.

Tests that check error positions continue to be disabled since
the synax parser records slightly different positions than the
go/parser (to be fixed).

Manually verified that selected *.go2 tests which don't report
errors pass. Type-checks the std library without errors.

Change-Id: If859b180bba8362db86c211eeb4dc2d46255df36
Reviewed-on: https://go-review.googlesource.com/c/go/+/246137
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-31 06:05:23 +00:00
Robert Griesemer deb678cebf [dev.go2go] go/types: add testcase for crash 9 of #39634
This test passes type-checking without problems but the
generated code causes a cmd/compile error (filed #40486).

Updates #39634.

Change-Id: If3dd28605f6d8792c6bd5bb032624e9a6140b2c0
Reviewed-on: https://go-review.googlesource.com/c/go/+/245742
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:50:09 +00:00
Robert Griesemer 15144bdc72 [dev.go2go] go/types: fix isParameterized predicate
When checking if a type is parameterized, we only care about
type parameters bound to the specific type, not "free" type
parameters. The old code simply looked for "any" type parameter.

Change-Id: I6a3fe5ac7e3150c5796d4b7576682ab3d4b8558f
Reviewed-on: https://go-review.googlesource.com/c/go/+/245741
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:50:01 +00:00
Robert Griesemer 88496095d2 [dev.go2go] go/types: remove incorrect assert and replace with explanatory comment
Addresses crash 26 of #39634.
Also, added test case for crash 25 which was fixed with
https://golang.org/cl/245739.

Updates #39634.

Change-Id: I19793eb79fce63052ba055cde0b1dafdd9476895
Reviewed-on: https://go-review.googlesource.com/c/go/+/245740
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 04:00:56 +00:00
Robert Griesemer f0e6640956 [dev.go2go] go/types: generic types in selector expressions must be instantiated
Addresses crash 24 of #39634.

Updates #39634.

Change-Id: If44e834834a07719e7f727d12cc24ac4af0997e6
Reviewed-on: https://go-review.googlesource.com/c/go/+/245739
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:57:09 +00:00
Robert Griesemer 0db4da527f [dev.go2go] go/types: don't crash in assignment due to prior errors
Addresses crash #12 of 39634.

Updates #39634.

Change-Id: Ie67545d21b6a1e80fcdec1b2eb101b69c25e2952
Reviewed-on: https://go-review.googlesource.com/c/go/+/245738
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:27:38 +00:00
Robert Griesemer d118bf7ce9 [dev.go2go] go/types: don't crash in lookup of incomplete interface
Also, update some comments.

Updates #39634.

Change-Id: I85c63e4b941e2bc04e8b5a59497fc47e5d578b8b
Reviewed-on: https://go-review.googlesource.com/c/go/+/245737
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-30 00:10:38 +00:00
Robert Griesemer df58427917 [dev.go2go] go/types: remove need to enumerate test files, clean up test handling
- Reorganize testdata directory to either contain single-file packages
or (one level of) sub-directories containing multi-file packages.

- Add TestTestdata that runs all the tests in testdata.

- Change TestCheck to only test files explicitly provided via -files.

Providing -v when running these tests now enumerates the packages.
For TestCheck it also prints the type-checking trace.

Change-Id: I66536881789234af030a0a2c9fc096822f593782
Reviewed-on: https://go-review.googlesource.com/c/go/+/244629
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 22:57:29 +00:00
Robert Griesemer 131fbfb416 [dev.go2go] go/types: remove need to enumerate examples and fixedbugs test files
Just traverse the respective directories.

Change-Id: I21432e23550d8331e61d3392e8488c81183ab6f0
Reviewed-on: https://go-review.googlesource.com/c/go/+/244628
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 20:13:27 +00:00
Robert Griesemer edac449852 [dev.go2go] go/types: clean up test support code and remove global variables
Change-Id: I152d2f4ca95f8217502d796ac49a8c96e5aba60b
Reviewed-on: https://go-review.googlesource.com/c/go/+/244627
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 19:40:13 +00:00
Robert Griesemer d0e6f20899 [dev.go2go] go/parser: make "type" optional in generic type declarations
Experiment: Make "type" keyword optional in generic type declarations when
it is clear that we can't have an array type declaration. This is the case
when we have one the following:

- more than one type parameter
- a type parameter with a constraint
- a trailing comma in the type parameter list

Change-Id: If6c473ba93b993a7c15ff2f7e7302709cc985f9e
Reviewed-on: https://go-review.googlesource.com/c/go/+/244623
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 18:10:25 +00:00
Robert Griesemer fad691cf11 [dev.go2go] go/types: don't crash with unsafe.Alignof/Sizeof on a type parameter value
Report an error instead for now until we have a better idea.
(It's unclear what these operations should do as they are
defined to return a compile-time constant which we can't
know in general.)

Fixes #40301.

Change-Id: I22a991311de117bc00d52b67b4ce862ea09d855a
Reviewed-on: https://go-review.googlesource.com/c/go/+/244622
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-24 00:25:37 +00:00
Ian Lance Taylor 64148d34c7 [dev.go2go] go/go2go: don't import renamed package twice
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>
2020-07-23 23:17:54 +00:00
Robert Griesemer 0030e13efb [dev.go2go] go/types: add a couple more interesting type inference examples
Change-Id: I28b31e013ae28a71adefb07cce0f47b505b57676
Reviewed-on: https://go-review.googlesource.com/c/go/+/244620
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 21:52:06 +00:00
Robert Griesemer de8501c203 [dev.go2go] go/parser: change value of UseBrackets constant (fix API check)
Passes all.bash again.

Change-Id: Ie558957b380cef937761faea69458980407bc8db
Reviewed-on: https://go-review.googlesource.com/c/go/+/244619
Reviewed-by: Robert Griesemer <gri@golang.org>
2020-07-23 21:19:31 +00:00