mirror of https://github.com/golang/go.git
go/types, types2: operand.AssignableTo must consider Alias types
Fixes regression from Go 1.22. For #67547. Change-Id: Id0d07d6b24e1eab6ed1c7476d9d9b82d28aee80a Reviewed-on: https://go-review.googlesource.com/c/go/+/587161 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Robert Findley <rfindley@google.com> 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>
This commit is contained in:
parent
44079f39eb
commit
8d464e4ae3
|
|
@ -260,7 +260,9 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
|
||||||
return true, 0 // avoid spurious errors
|
return true, 0 // avoid spurious errors
|
||||||
}
|
}
|
||||||
|
|
||||||
V := x.typ
|
origT := T
|
||||||
|
V := Unalias(x.typ)
|
||||||
|
T = Unalias(T)
|
||||||
|
|
||||||
// x's type is identical to T
|
// x's type is identical to T
|
||||||
if Identical(V, T) {
|
if Identical(V, T) {
|
||||||
|
|
@ -386,7 +388,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
|
||||||
x.typ = V.typ
|
x.typ = V.typ
|
||||||
ok, code = x.assignableTo(check, T, cause)
|
ok, code = x.assignableTo(check, T, cause)
|
||||||
if !ok {
|
if !ok {
|
||||||
errorf("cannot assign %s (in %s) to %s", V.typ, Vp, T)
|
errorf("cannot assign %s (in %s) to %s", V.typ, Vp, origT)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,9 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
|
||||||
return true, 0 // avoid spurious errors
|
return true, 0 // avoid spurious errors
|
||||||
}
|
}
|
||||||
|
|
||||||
V := x.typ
|
origT := T
|
||||||
|
V := Unalias(x.typ)
|
||||||
|
T = Unalias(T)
|
||||||
|
|
||||||
// x's type is identical to T
|
// x's type is identical to T
|
||||||
if Identical(V, T) {
|
if Identical(V, T) {
|
||||||
|
|
@ -390,7 +392,7 @@ func (x *operand) assignableTo(check *Checker, T Type, cause *string) (bool, Cod
|
||||||
x.typ = V.typ
|
x.typ = V.typ
|
||||||
ok, code = x.assignableTo(check, T, cause)
|
ok, code = x.assignableTo(check, T, cause)
|
||||||
if !ok {
|
if !ok {
|
||||||
errorf("cannot assign %s (in %s) to %s", V.typ, Vp, T)
|
errorf("cannot assign %s (in %s) to %s", V.typ, Vp, origT)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,28 @@ func _[P int | string]() {
|
||||||
// preserve target type name A in error messages when using Alias types
|
// preserve target type name A in error messages when using Alias types
|
||||||
// (test are run with and without Alias types enabled, so we need to
|
// (test are run with and without Alias types enabled, so we need to
|
||||||
// keep both A and int in the error message)
|
// keep both A and int in the error message)
|
||||||
_ = A(p /* ERRORx "cannot convert string .* to type (A|int)" */)
|
_ = A(p /* ERRORx `cannot convert string \(in P\) to type (A|int)` */)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _[P struct{ x int }]() {
|
||||||
|
var x struct{ x int }
|
||||||
|
type A = P
|
||||||
|
var _ A = x // assignment must be valid
|
||||||
|
}
|
||||||
|
|
||||||
|
func _[P struct{ x int }]() {
|
||||||
|
type A = P
|
||||||
|
var x A
|
||||||
|
var _ struct{ x int } = x // assignment must be valid
|
||||||
|
}
|
||||||
|
|
||||||
|
func _[P []int | struct{}]() {
|
||||||
|
type A = []int
|
||||||
|
var a A
|
||||||
|
var p P
|
||||||
|
// preserve target type name A in error messages when using Alias types
|
||||||
|
a = p // ERRORx `cannot assign struct{} \(in P\) to (A|\[\]int)`
|
||||||
|
_ = a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test case for go.dev/issue/67540.
|
// Test case for go.dev/issue/67540.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue