From c6dc95eb7e8760d6224e8ecded5f3c4ddff9d639 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Sat, 31 Jul 2021 10:59:22 +0200 Subject: [PATCH] interp: improve handling of interface struct field Wrap non empty interface value in struct field, to allow method lookup. Fixes #1208. --- _test/issue-1208.go | 23 +++++++++++++++++++++++ interp/run.go | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 _test/issue-1208.go diff --git a/_test/issue-1208.go b/_test/issue-1208.go new file mode 100644 index 000000000..9d2ee4aa8 --- /dev/null +++ b/_test/issue-1208.go @@ -0,0 +1,23 @@ +package main + +type Enabler interface { + Enabled() bool +} + +type Logger struct { + core Enabler +} + +func (log *Logger) GetCore() Enabler { return log.core } + +type T struct{} + +func (t *T) Enabled() bool { return true } + +func main() { + base := &Logger{&T{}} + println(base.GetCore().Enabled()) +} + +// Output: +// true diff --git a/interp/run.go b/interp/run.go index 745a5c7bc..1f839be32 100644 --- a/interp/run.go +++ b/interp/run.go @@ -2543,6 +2543,8 @@ func doComposite(n *node, hasType bool, keyed bool) { values[fieldIndex] = genValueInterfaceArray(val) case isRecursiveType(ft, rft): values[fieldIndex] = genValueRecursiveInterface(val, rft) + case isInterfaceSrc(ft) && !isEmptyInterface(ft): + values[fieldIndex] = genValueInterface(val) case isInterface(ft): values[fieldIndex] = genInterfaceWrapper(val, rft) default: