mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 02:57:46 +00:00
reflect: Value.Set: fix direction of assignment check
This commit is contained in:
@@ -907,7 +907,7 @@ func (it *MapIter) Next() bool {
|
||||
|
||||
func (v Value) Set(x Value) {
|
||||
v.checkAddressable()
|
||||
if !v.typecode.AssignableTo(x.typecode) {
|
||||
if !x.typecode.AssignableTo(v.typecode) {
|
||||
panic("reflect: cannot set")
|
||||
}
|
||||
|
||||
|
||||
@@ -504,6 +504,15 @@ func TestTinyNumMethods(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAssignableTo(t *testing.T) {
|
||||
var a any
|
||||
refa := ValueOf(&a).Elem()
|
||||
refa.Set(ValueOf(4))
|
||||
if got, want := refa.Interface().(int), 4; got != want {
|
||||
t.Errorf("AssignableTo / Set failed, got %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func equal[T comparable](a, b []T) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user