Skip to content

Commit

Permalink
interp: improve handling of interface struct field
Browse files Browse the repository at this point in the history
Wrap non empty interface value  in struct field, to allow method
lookup.

Fixes #1208.
  • Loading branch information
mvertes authored and traefiker committed Aug 6, 2021
1 parent d4e25f0 commit 3bf4b41
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions _test/issue-1208.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,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:
Expand Down

0 comments on commit 3bf4b41

Please sign in to comment.