]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: comp literals to accept type sets with single underlying...
authorRobert Griesemer <gri@golang.org>
Fri, 22 Oct 2021 03:01:51 +0000 (20:01 -0700)
committerRobert Griesemer <gri@golang.org>
Sat, 23 Oct 2021 16:18:19 +0000 (16:18 +0000)
Change-Id: Ib51bcdf023910d244739ec176880a16e700851e7
Reviewed-on: https://go-review.googlesource.com/c/go/+/357915
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/expr.go
src/cmd/compile/internal/types2/testdata/check/compliterals.go2 [new file with mode: 0644]

index 1001554739614cc01d6c301c8408baa6efd420bd..3a39de74065f604a67df26323c53df16b93593ed 100644 (file)
@@ -1253,7 +1253,7 @@ func (check *Checker) exprInternal(x *operand, e syntax.Expr, hint Type) exprKin
                        goto Error
                }
 
-               switch utyp := optype(base).(type) {
+               switch utyp := singleUnder(base).(type) {
                case *Struct:
                        if len(e.ElemList) == 0 {
                                break
diff --git a/src/cmd/compile/internal/types2/testdata/check/compliterals.go2 b/src/cmd/compile/internal/types2/testdata/check/compliterals.go2
new file mode 100644 (file)
index 0000000..60eac97
--- /dev/null
@@ -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}}
+}