Skip to content

Commit

Permalink
fix: assign untyped value to typed var may require type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Oct 20, 2019
1 parent e193d95 commit ac504a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions _test/assign10.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func main() {
var a uint
a = 1 + 2
println(a)
}

// Output:
// 3
2 changes: 2 additions & 0 deletions interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ func assign(n *node) {
svalue[i] = func(*frame) reflect.Value { return reflect.New(t).Elem() }
case isRecursiveStruct(dest.typ, dest.typ.rtype):
svalue[i] = genValueInterfacePtr(src)
case src.typ.untyped && !dest.typ.untyped:
svalue[i] = genValueAs(src, dest.typ.TypeOf())
default:
svalue[i] = genValue(src)
}
Expand Down

0 comments on commit ac504a2

Please sign in to comment.