Skip to content

Commit

Permalink
fix: handle nil interface conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma committed Jun 2, 2020
1 parent 01e4cde commit d5217f7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions _test/interface43.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import "fmt"

func main() {
v := interface{}(nil)

fmt.Println(v)
}

// Output:
// <nil>
3 changes: 3 additions & 0 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ func convert(n *node) {
next := getExec(n.tnext)

if c.isNil() { // convert nil to type
if n.child[0].typ.cat == interfaceT {
typ = reflect.TypeOf((*valueInterface)(nil)).Elem()
}
n.exec = func(f *frame) bltn {
dest(f).Set(reflect.New(typ).Elem())
return next
Expand Down

0 comments on commit d5217f7

Please sign in to comment.