fix: correct index for embedded binary method receiver
When searching for a binary method on structures, look up on embedded fields first, otherwise the resulting index is incorrect, as reflect.Type.MethodByName succeeds also on container struct. Fixes #834.
This commit is contained in:
@@ -1244,21 +1244,19 @@ func (t *itype) lookupBinMethod(name string) (m reflect.Method, index []int, isP
|
||||
if t.cat == ptrT {
|
||||
return t.val.lookupBinMethod(name)
|
||||
}
|
||||
for i, f := range t.field {
|
||||
if f.embed {
|
||||
if m2, index2, isPtr2, ok2 := f.typ.lookupBinMethod(name); ok2 {
|
||||
index = append([]int{i}, index2...)
|
||||
return m2, index, isPtr2, ok2
|
||||
}
|
||||
}
|
||||
}
|
||||
m, ok = t.TypeOf().MethodByName(name)
|
||||
if !ok {
|
||||
m, ok = reflect.PtrTo(t.TypeOf()).MethodByName(name)
|
||||
isPtr = ok
|
||||
}
|
||||
if !ok {
|
||||
for i, f := range t.field {
|
||||
if f.embed {
|
||||
if m2, index2, isPtr2, ok2 := f.typ.lookupBinMethod(name); ok2 {
|
||||
index = append([]int{i}, index2...)
|
||||
return m2, index, isPtr2, ok2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return m, index, isPtr, ok
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user