Skip to content

Commit

Permalink
fix: detect untyped values when importing from binary packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Dec 13, 2019
1 parent 275391c commit 7a0c09f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions _test/str4.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "unicode/utf8"

func main() {
r, _ := utf8.DecodeRuneInString("Hello")
println(r < utf8.RuneSelf)
}

// Output:
// true
16 changes: 15 additions & 1 deletion interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
n.typ = &itype{cat: valueT, rtype: s.Type().Elem()}
} else {
n.kind = rvalueExpr
n.typ = &itype{cat: valueT, rtype: s.Type()}
n.typ = &itype{cat: valueT, rtype: s.Type(), untyped: isValueUntyped(s)}
n.rval = s
}
n.gen = nop
Expand Down Expand Up @@ -1825,3 +1825,17 @@ func arrayTypeLen(n *node) int {
}
return max + 1
}

// isValueUntyped returns true if value is untyped
func isValueUntyped(v reflect.Value) bool {
// Consider only untyped constant values.
if v.CanSet() {
return false
}
// Consider only values of default numerical types.
switch v.Type().Kind() {
case reflect.Int, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float64, reflect.Complex128:
return true
}
return false
}

0 comments on commit 7a0c09f

Please sign in to comment.