]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: remove remaining references to coreType in literals.go
authorRobert Griesemer <gri@golang.org>
Wed, 26 Feb 2025 23:23:59 +0000 (15:23 -0800)
committerGopher Robot <gobot@golang.org>
Mon, 3 Mar 2025 19:26:34 +0000 (11:26 -0800)
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>
src/cmd/compile/internal/types2/literals.go
src/go/types/literals.go
src/internal/types/testdata/fixedbugs/issue51335.go

index b81d51564ca00b4bd211695849d8a17aebfaf23a..da5b03d8eab39c3b6b7bd50a658a98b9b9cb60dc 100644 (file)
@@ -129,7 +129,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
                typ = hint
                base = typ
                // *T implies &T{}
-               if b, ok := deref(coreType(base)); ok {
+               if b, ok := deref(commonUnder(check, base, nil)); ok {
                        base = b
                }
                isElem = true
@@ -142,7 +142,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
                base = typ
        }
 
-       switch utyp := coreType(base).(type) {
+       switch utyp := commonUnder(check, base, nil).(type) {
        case *Struct:
                // Prevent crash if the struct referred to is not yet set up.
                // See analogous comment for *Array.
@@ -330,7 +330,7 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
                        }
                        var cause string
                        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)
                        x.mode = invalid
index d3102d4f911eb6298e33d02f3077b4f455c5b352..ebc25957ed87cfa1eae5fdba0a719bdc7157a32d 100644 (file)
@@ -133,7 +133,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
                typ = hint
                base = typ
                // *T implies &T{}
-               if b, ok := deref(coreType(base)); ok {
+               if b, ok := deref(commonUnder(check, base, nil)); ok {
                        base = b
                }
                isElem = true
@@ -146,7 +146,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
                base = typ
        }
 
-       switch utyp := coreType(base).(type) {
+       switch utyp := commonUnder(check, base, nil).(type) {
        case *Struct:
                // Prevent crash if the struct referred to is not yet set up.
                // See analogous comment for *Array.
@@ -334,7 +334,7 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
                        }
                        var cause string
                        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)
                        x.mode = invalid
index 04dc04e1d7a36bd721217a8b80904fdde3cd1610..5eb52138430ab508c561ea3bf65c3f33937ec50f 100644 (file)
@@ -8,9 +8,9 @@ type S1 struct{}
 type S2 struct{}
 
 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]() {
-       _= []P{{ /* ERROR "invalid composite literal element type P (no core type)" */ }}
+       _= []P{{ /* ERROR "invalid composite literal element type P (no common underlying type)" */ }}
 }