Skip to content

Commit

Permalink
interp: fix retrieving the string value of an interface
Browse files Browse the repository at this point in the history
Thanks to @bailsman for providing first insight, in addition to
raising the issue.

Fixes #1342.
  • Loading branch information
mvertes committed May 19, 2022
1 parent 25edcfe commit 4ed9ccb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions _test/issue-1342.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import "fmt"

func main() {
var a interface{}
a = "a"
fmt.Println(a, a == "a")
}

// Output:
// a true
5 changes: 5 additions & 0 deletions interp/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,5 +595,10 @@ func genComplex(n *node) func(*frame) complex128 {

func genValueString(n *node) func(*frame) (reflect.Value, string) {
value := genValue(n)

if n.typ.TypeOf().Kind() == reflect.Interface {
return func(f *frame) (reflect.Value, string) { v := value(f); return v, v.Elem().String() }
}

return func(f *frame) (reflect.Value, string) { v := value(f); return v, v.String() }
}

0 comments on commit 4ed9ccb

Please sign in to comment.