Skip to content

Commit c812b97

Browse files
committed
go/types: comp literals to accept type sets with single underlying types
This is a clean port of CL 357915 to go/types. Change-Id: Idf5850a8bdcf3596c561c97bcd60539945139743 Reviewed-on: https://go-review.googlesource.com/c/go/+/359877 Trust: Robert Findley <[email protected]> Run-TryBot: Robert Findley <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 71e6ab8 commit c812b97

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/go/types/expr.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
12231223
goto Error
12241224
}
12251225

1226-
switch utyp := optype(base).(type) {
1226+
switch utyp := singleUnder(base).(type) {
12271227
case *Struct:
12281228
if len(e.Elts) == 0 {
12291229
break
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2012 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Composite literals with parameterized types
6+
7+
package comp_literals
8+
9+
type myStruct struct {
10+
f int
11+
}
12+
13+
type slice[E any] []E
14+
15+
func struct_literals[S struct{f int}|myStruct]() {
16+
_ = S{}
17+
_ = S{0}
18+
_ = S{f: 0}
19+
20+
_ = slice[int]{1, 2, 3}
21+
_ = slice[S]{{}, {0}, {f:0}}
22+
}

0 commit comments

Comments
 (0)