interp: fix detection of binary types implementing interfaces
Fixes #1136.
This commit is contained in:
12
_test/issue-1136.go
Normal file
12
_test/issue-1136.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func main() {
|
||||
x := io.LimitedReader{}
|
||||
y := io.Reader(&x)
|
||||
fmt.Println(y)
|
||||
}
|
||||
@@ -1558,7 +1558,7 @@ func (t *itype) frameType() (r reflect.Type) {
|
||||
}
|
||||
|
||||
func (t *itype) implements(it *itype) bool {
|
||||
if t.cat == valueT {
|
||||
if isBin(t) {
|
||||
return t.TypeOf().Implements(it.TypeOf())
|
||||
}
|
||||
return t.methods().contains(it.methods())
|
||||
@@ -1730,6 +1730,17 @@ func isInterface(t *itype) bool {
|
||||
return isInterfaceSrc(t) || t.TypeOf() != nil && t.TypeOf().Kind() == reflect.Interface
|
||||
}
|
||||
|
||||
func isBin(t *itype) bool {
|
||||
switch t.cat {
|
||||
case valueT:
|
||||
return true
|
||||
case aliasT, ptrT:
|
||||
return isBin(t.val)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func isStruct(t *itype) bool {
|
||||
// Test first for a struct category, because a recursive interpreter struct may be
|
||||
// represented by an interface{} at reflect level.
|
||||
|
||||
Reference in New Issue
Block a user