Skip to content

Commit 80b5c20

Browse files
author
Ben Krieger
committed
reflect: allow Value.Set for slice->array, but not AssignableTo
1 parent a6351e8 commit 80b5c20

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

src/reflect/type.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,14 +1001,6 @@ func (t *rawType) AssignableTo(u Type) bool {
10011001
return true
10021002
}
10031003

1004-
if u.Kind() == Array && t.Kind() == Slice {
1005-
return u.Elem().(*rawType) == t.Elem().(*rawType)
1006-
}
1007-
1008-
if (u.Kind() == Pointer && u.Elem().Kind() == Array) && t.Kind() == Slice {
1009-
return u.Elem().Elem().(*rawType) == t.Elem().(*rawType)
1010-
}
1011-
10121004
if u.Kind() == Interface && u.NumMethod() == 0 {
10131005
return true
10141006
}

src/reflect/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ func (it *MapIter) Next() bool {
10831083
func (v Value) Set(x Value) {
10841084
v.checkAddressable()
10851085
v.checkRO()
1086-
if !x.typecode.AssignableTo(v.typecode) {
1086+
if !x.typecode.AssignableTo(v.typecode) && !x.typecode.ConvertibleTo(v.typecode) {
10871087
panic("reflect.Value.Set: value of type " + x.typecode.String() + " cannot be assigned to type " + v.typecode.String())
10881088
}
10891089

0 commit comments

Comments
 (0)