mirror of https://github.com/golang/go.git
go/types, types2: remove remaining references to coreType in literals.go
For now, use commonUnder (formerly called sharedUnder) and update error messages and comments. We can provide better error messages in individual cases eventually. For #70128. Change-Id: I906ba9a0c768f6499c1683dc9be3ad27da8007a9 Reviewed-on: https://go-review.googlesource.com/c/go/+/653156 Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
26ba61dfad
commit
05354fc3b4
|
|
@ -129,7 +129,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
|
||||||
typ = hint
|
typ = hint
|
||||||
base = typ
|
base = typ
|
||||||
// *T implies &T{}
|
// *T implies &T{}
|
||||||
if b, ok := deref(coreType(base)); ok {
|
if b, ok := deref(commonUnder(check, base, nil)); ok {
|
||||||
base = b
|
base = b
|
||||||
}
|
}
|
||||||
isElem = true
|
isElem = true
|
||||||
|
|
@ -142,7 +142,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
|
||||||
base = typ
|
base = typ
|
||||||
}
|
}
|
||||||
|
|
||||||
switch utyp := coreType(base).(type) {
|
switch utyp := commonUnder(check, base, nil).(type) {
|
||||||
case *Struct:
|
case *Struct:
|
||||||
// Prevent crash if the struct referred to is not yet set up.
|
// Prevent crash if the struct referred to is not yet set up.
|
||||||
// See analogous comment for *Array.
|
// See analogous comment for *Array.
|
||||||
|
|
@ -330,7 +330,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
|
||||||
}
|
}
|
||||||
var cause string
|
var cause string
|
||||||
if utyp == nil {
|
if utyp == nil {
|
||||||
cause = " (no core type)"
|
cause = " (no common underlying type)"
|
||||||
}
|
}
|
||||||
check.errorf(e, InvalidLit, "invalid composite literal%s type %s%s", qualifier, typ, cause)
|
check.errorf(e, InvalidLit, "invalid composite literal%s type %s%s", qualifier, typ, cause)
|
||||||
x.mode = invalid
|
x.mode = invalid
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
|
||||||
typ = hint
|
typ = hint
|
||||||
base = typ
|
base = typ
|
||||||
// *T implies &T{}
|
// *T implies &T{}
|
||||||
if b, ok := deref(coreType(base)); ok {
|
if b, ok := deref(commonUnder(check, base, nil)); ok {
|
||||||
base = b
|
base = b
|
||||||
}
|
}
|
||||||
isElem = true
|
isElem = true
|
||||||
|
|
@ -146,7 +146,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
|
||||||
base = typ
|
base = typ
|
||||||
}
|
}
|
||||||
|
|
||||||
switch utyp := coreType(base).(type) {
|
switch utyp := commonUnder(check, base, nil).(type) {
|
||||||
case *Struct:
|
case *Struct:
|
||||||
// Prevent crash if the struct referred to is not yet set up.
|
// Prevent crash if the struct referred to is not yet set up.
|
||||||
// See analogous comment for *Array.
|
// See analogous comment for *Array.
|
||||||
|
|
@ -334,7 +334,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
|
||||||
}
|
}
|
||||||
var cause string
|
var cause string
|
||||||
if utyp == nil {
|
if utyp == nil {
|
||||||
cause = " (no core type)"
|
cause = " (no common underlying type)"
|
||||||
}
|
}
|
||||||
check.errorf(e, InvalidLit, "invalid composite literal%s type %s%s", qualifier, typ, cause)
|
check.errorf(e, InvalidLit, "invalid composite literal%s type %s%s", qualifier, typ, cause)
|
||||||
x.mode = invalid
|
x.mode = invalid
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ type S1 struct{}
|
||||||
type S2 struct{}
|
type S2 struct{}
|
||||||
|
|
||||||
func _[P *S1|*S2]() {
|
func _[P *S1|*S2]() {
|
||||||
_= []P{{ /* ERROR "invalid composite literal element type P (no core type)" */ }}
|
_= []P{{ /* ERROR "invalid composite literal element type P (no common underlying type)" */ }}
|
||||||
}
|
}
|
||||||
|
|
||||||
func _[P *S1|S1]() {
|
func _[P *S1|S1]() {
|
||||||
_= []P{{ /* ERROR "invalid composite literal element type P (no core type)" */ }}
|
_= []P{{ /* ERROR "invalid composite literal element type P (no common underlying type)" */ }}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue