aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/types2/examples/types.go2
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/types2/examples/types.go2')
-rw-r--r--src/cmd/compile/internal/types2/examples/types.go218
1 files changed, 17 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/types2/examples/types.go2 b/src/cmd/compile/internal/types2/examples/types.go2
index f094880c49..a081f61c01 100644
--- a/src/cmd/compile/internal/types2/examples/types.go2
+++ b/src/cmd/compile/internal/types2/examples/types.go2
@@ -261,4 +261,20 @@ func _(_ comparable /* ERROR comparable */ , _ C /* ERROR comparable */ )
func _() {
var _ comparable /* ERROR comparable */
var _ C /* ERROR comparable */
-} \ No newline at end of file
+}
+
+// Type parameters are never const types, i.e., it's
+// not possible to declare a constant of type parameter type.
+// (If a type list contains just a single const type, we could
+// allow it, but such type lists don't make much sense in the
+// first place.)
+func _[T interface { type int, float64 }]() {
+ // not valid
+ const _ = T /* ERROR not constant */ (0)
+ const _ T /* ERROR invalid constant type T */ = 1
+
+ // valid
+ var _ = T(0)
+ var _ T = 1
+ _ = T(0)
+}