aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2022-02-14 16:33:39 -0500
committerRobert Findley <rfindley@google.com>2022-02-15 14:54:27 +0000
commit76bd8ea9e133293d2a8253f01f66c1ca9add64e6 (patch)
tree23622490773a68feb03ae9f49f83f9620456faea
parentdd7194b28ec7762ace737efc0f0a62c96cb4a4ad (diff)
downloadgo-76bd8ea9e133293d2a8253f01f66c1ca9add64e6.tar.gz
go-76bd8ea9e133293d2a8253f01f66c1ca9add64e6.zip
go/types, types2: add tests for literals in type parameter lists
Add tests that verify consistent behavior of go/types and types2 with respect to potentially ambiguous type parameter lists. For #49482 Change-Id: I3386d4fa3eb91f2a8ea0987372ca40a6962de886 Reviewed-on: https://go-review.googlesource.com/c/go/+/385756 Trust: Robert Findley <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
-rw-r--r--src/cmd/compile/internal/types2/testdata/fixedbugs/issue49482.go225
-rw-r--r--src/go/types/testdata/fixedbugs/issue49482.go228
2 files changed, 53 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49482.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49482.go2
new file mode 100644
index 0000000000..f289d2e52d
--- /dev/null
+++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue49482.go2
@@ -0,0 +1,25 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file is tested when running "go test -run Manual"
+// without source arguments. Use for one-off debugging.
+
+package p
+
+// The following is OK, per the special handling for type literals discussed in issue #49482.
+type _[P *struct{}] struct{}
+type _[P *int,] int
+type _[P (*int),] int
+
+const P = 2 // declare P to avoid noisy 'undeclared name' errors below.
+
+// The following parse as invalid array types.
+type _[P *int /* ERROR "int \(type\) is not an expression" */ ] int
+type _[P /* ERROR non-function P */ (*int)] int
+
+// The following should be parsed as a generic type, but is instead parsed as an array type.
+type _[P *struct /* ERROR "not an expression" */ {}| int /* ERROR "not an expression" */ ] struct{}
+
+// The following fails to parse, due to the '~'
+type _[P *struct /* ERROR "not an expression" */ {}|~ /* ERROR "unexpected ~" */ int] struct{}
diff --git a/src/go/types/testdata/fixedbugs/issue49482.go2 b/src/go/types/testdata/fixedbugs/issue49482.go2
new file mode 100644
index 0000000000..4c6579ed68
--- /dev/null
+++ b/src/go/types/testdata/fixedbugs/issue49482.go2
@@ -0,0 +1,28 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file is tested when running "go test -run Manual"
+// without source arguments. Use for one-off debugging.
+
+package p
+
+// The following is OK, per the special handling for type literals discussed in issue #49482.
+type _[P *struct{}] struct{}
+type _[P *int,] int
+type _[P (*int),] int
+
+const P = 2 // declare P to avoid noisy 'undeclared name' errors below.
+
+// The following parse as invalid array types.
+type _[P *int /* ERROR "int \(type\) is not an expression" */ ] int
+type _[P /* ERROR non-function P */ (*int)] int
+
+// The following should be parsed as a generic type, but is instead parsed as an array type.
+type _[P *struct /* ERROR "expected expression" */ {}| int /* ERROR "not an expression" */ ] struct{}
+
+// The following fails to parse, due to the '~'
+type _[P *struct /* ERROR "expected expression" */ {}|~ /* ERROR "expected operand" */ int] struct{}
+
+// This is fragile: 'var' synchronizes the parser, and we absorb the rest of the errors.
+var /* ERROR "expected ']'" */ _ /* ERROR "value or type" */