From b1ef9251d41488d4ef4f7daee26ede712f7058a6 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Fri, 11 Jun 2021 17:58:11 +0200 Subject: [PATCH] interp: fix detection of binary types implementing interfaces Fixes #1136. --- _test/issue-1136.go | 12 ++++++++++++ interp/type.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 _test/issue-1136.go diff --git a/_test/issue-1136.go b/_test/issue-1136.go new file mode 100644 index 00000000..a3d729c9 --- /dev/null +++ b/_test/issue-1136.go @@ -0,0 +1,12 @@ +package main + +import ( + "fmt" + "io" +) + +func main() { + x := io.LimitedReader{} + y := io.Reader(&x) + fmt.Println(y) +} diff --git a/interp/type.go b/interp/type.go index a7e8a0f1..7fb6792c 100644 --- a/interp/type.go +++ b/interp/type.go @@ -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.