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" */