Skip to content

Commit

Permalink
interp: improve handling of aliased types
Browse files Browse the repository at this point in the history
Avoid to test directly for a type category, as it may give wrong
results for aliased types, where the interesting category remains
masked.  Instead, use some property helpers, such as isFuncSrc,
isPtrSrc and isInterfaceSrc to check if a type is of source function,
source pointer or source interface respectively (versus runtime
defined function, pointer or interface).

Fixes #1068.
  • Loading branch information
mvertes authored Apr 14, 2021
1 parent 3e3f8d5 commit a241119
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 95 deletions.
19 changes: 19 additions & 0 deletions _test/issue-1068.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

type I interface {
Hello()
}

type T struct{}

func (t T) Hello() { println("hello") }

type I2 I

func main() {
var i I2 = T{}
i.Hello()
}

// Output:
// hello
2 changes: 1 addition & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func (interp *Interpreter) cfg(root *node, importPath string) ([]*node, error) {
dest.gen = nop
case isFuncField(dest):
// Setting a struct field of function type requires an extra step. Do not optimize.
case isCall(src) && dest.typ.cat != interfaceT && !isRecursiveField(dest) && n.kind != defineStmt:
case isCall(src) && !isInterfaceSrc(dest.typ) && !isRecursiveField(dest) && n.kind != defineStmt:
// Call action may perform the assignment directly.
n.gen = nop
src.level = level
Expand Down
Loading

0 comments on commit a241119

Please sign in to comment.