mirror of
https://github.com/golang/go.git
synced 2025-05-06 08:03:03 +00:00
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 <rfindley@google.com> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
71e6ab8f95
commit
c812b97ec6
@ -1223,7 +1223,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind {
|
|||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
|
|
||||||
switch utyp := optype(base).(type) {
|
switch utyp := singleUnder(base).(type) {
|
||||||
case *Struct:
|
case *Struct:
|
||||||
if len(e.Elts) == 0 {
|
if len(e.Elts) == 0 {
|
||||||
break
|
break
|
||||||
|
22
src/go/types/testdata/check/compliterals.go2
vendored
Normal file
22
src/go/types/testdata/check/compliterals.go2
vendored
Normal file
@ -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}}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user