]> Cypherpunks.ru repositories - gostls13.git/commit
go/types, types2: consider type parameters for cycle detection
authorRobert Griesemer <gri@golang.org>
Sat, 15 Jan 2022 01:42:20 +0000 (17:42 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 24 Jan 2022 21:27:28 +0000 (21:27 +0000)
commit2abfa30f9e0041e932411816ba07d68060eec304
tree45a7aab53fb5292b2a1c96512dfb0fb8bfdc3f1a
parent7520c080b45e9493b289d622aed8d8a0da528089
go/types, types2: consider type parameters for cycle detection

In validType, when we see an instantiated type, proceed as with
non-generic types but provide an environment in which to look up
the values (the corresponding type arguments) of type parameters
of the instantiated type. For each type parameter for which there
is a type argument, proceed with validating that type argument.
This corresponds to applying validType to the instantiated type
without actually instantiating the type (and running into infinite
instantiations in case of invalid recursive types).

Also, when creating a type instance, use the correct source position
for the instance (the start of the qualified identifier if we have an
imported type).

Fixes #48962.

Change-Id: I196c78bf066e4a56284d53368b2eb71bd8d8a780
Reviewed-on: https://go-review.googlesource.com/c/go/+/379414
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
21 files changed:
src/cmd/compile/internal/types2/testdata/check/issues.go2
src/cmd/compile/internal/types2/testdata/check/typeinst.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39634.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39938.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48951.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48962.go2 [new file with mode: 0644]
src/cmd/compile/internal/types2/testdata/fixedbugs/issue49043.go2
src/cmd/compile/internal/types2/typexpr.go
src/cmd/compile/internal/types2/validtype.go
src/go/types/testdata/check/issues.go2
src/go/types/testdata/check/typeinst.go2
src/go/types/testdata/fixedbugs/issue39634.go2
src/go/types/testdata/fixedbugs/issue39938.go2
src/go/types/testdata/fixedbugs/issue48951.go2
src/go/types/testdata/fixedbugs/issue48962.go2 [new file with mode: 0644]
src/go/types/testdata/fixedbugs/issue49043.go2
src/go/types/typexpr.go
src/go/types/validtype.go
test/typeparam/issue48962.dir/a.go [new file with mode: 0644]
test/typeparam/issue48962.dir/b.go [new file with mode: 0644]
test/typeparam/issue48962.go