Skip to content

Commit

Permalink
go/types, types2: coreType/String must consider Alias types
Browse files Browse the repository at this point in the history
Fixes regression from Go 1.22.

For #67547.

Change-Id: Idd319b9d2a73c824caa2c821df0e2fcd4f58cb08
Reviewed-on: https://go-review.googlesource.com/c/go/+/587176
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
  • Loading branch information
griesemer authored and gopherbot committed May 21, 2024
1 parent 814e72f commit 4b77847
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/cmd/compile/internal/types2/under.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func under(t Type) Type {
// identical element types), the single underlying type is the restricted
// channel type if the restrictions are always the same, or nil otherwise.
func coreType(t Type) Type {
t = Unalias(t)
tpar, _ := t.(*TypeParam)
if tpar == nil {
return under(t)
Expand Down Expand Up @@ -51,6 +52,7 @@ func coreType(t Type) Type {
// and strings as identical. In this case, if successful and we saw
// a string, the result is of type (possibly untyped) string.
func coreString(t Type) Type {
t = Unalias(t)
tpar, _ := t.(*TypeParam)
if tpar == nil {
return under(t) // string or untyped string
Expand Down
2 changes: 2 additions & 0 deletions src/go/types/under.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/internal/types/testdata/fixedbugs/issue67547.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,15 @@ func _[P int]() {
type A = P
_ = A(0) // don't crash with this conversion
}

func _[P []int]() {
type A = P
_ = make(A, 10) // don't report an error for A
}

func _[P string]() {
var t []byte
type A = P
var s A
copy(t, s) // don't report an error for s
}

0 comments on commit 4b77847

Please sign in to comment.