aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/go/types/expr.go2
-rw-r--r--src/go/types/testdata/check/compliterals.go222
2 files changed, 23 insertions, 1 deletions
diff --git a/src/go/types/expr.go b/src/go/types/expr.go
index 3a09dfd85f..8b26e64971 100644
--- a/src/go/types/expr.go
+++ b/src/go/types/expr.go
@@ -1223,7 +1223,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
goto Error
}
- switch utyp := optype(base).(type) {
+ switch utyp := singleUnder(base).(type) {
case *Struct:
if len(e.Elts) == 0 {
break
diff --git a/src/go/types/testdata/check/compliterals.go2 b/src/go/types/testdata/check/compliterals.go2
new file mode 100644
index 0000000000..60eac97a3f
--- /dev/null
+++ b/src/go/types/testdata/check/compliterals.go2
@@ -0,0 +1,22 @@
+// Copyright 2012 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.
+
+// Composite literals with parameterized types
+
+package comp_literals
+
+type myStruct struct {
+ f int
+}
+
+type slice[E any] []E
+
+func struct_literals[S struct{f int}|myStruct]() {
+ _ = S{}
+ _ = S{0}
+ _ = S{f: 0}
+
+ _ = slice[int]{1, 2, 3}
+ _ = slice[S]{{}, {0}, {f:0}}
+}