diff --git a/_test/str4.go b/_test/str4.go new file mode 100644 index 000000000..ab68b2af8 --- /dev/null +++ b/_test/str4.go @@ -0,0 +1,11 @@ +package main + +import "unicode/utf8" + +func main() { + r, _ := utf8.DecodeRuneInString("Hello") + println(r < utf8.RuneSelf) +} + +// Output: +// true diff --git a/interp/cfg.go b/interp/cfg.go index 7c86081c8..801ff5b11 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -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 @@ -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 +}