diff --git a/_test/str1.go b/_test/str1.go new file mode 100644 index 00000000..e504b3a9 --- /dev/null +++ b/_test/str1.go @@ -0,0 +1,14 @@ +package main + +const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + +func main() { + for i, r := range itoa64 { + if r == '1' { + println(i) + } + } +} + +// Output: +// 3 diff --git a/_test/str2.go b/_test/str2.go new file mode 100644 index 00000000..91433f17 --- /dev/null +++ b/_test/str2.go @@ -0,0 +1,12 @@ +package main + +const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + +func main() { + if itoa64[3] == '1' { + println("ok") + } +} + +// Output: +// ok diff --git a/interp/cfg.go b/interp/cfg.go index 062af396..55470379 100644 --- a/interp/cfg.go +++ b/interp/cfg.go @@ -74,6 +74,9 @@ func (interp *Interpreter) Cfg(root *Node) ([]*Node, error) { n.anc.gen = rangeMap ktyp = &Type{cat: ValueT, rtype: typ.Key()} vtyp = &Type{cat: ValueT, rtype: typ.Elem()} + case reflect.String: + ktyp = scope.getType("int") + vtyp = scope.getType("byte") case reflect.Array, reflect.Slice: ktyp = scope.getType("int") vtyp = &Type{cat: ValueT, rtype: typ.Elem()} @@ -82,6 +85,9 @@ func (interp *Interpreter) Cfg(root *Node) ([]*Node, error) { n.anc.gen = rangeMap ktyp = o.typ.key vtyp = o.typ.val + case StringT: + ktyp = scope.getType("int") + vtyp = scope.getType("byte") case ArrayT: ktyp = scope.getType("int") vtyp = o.typ.val @@ -576,7 +582,7 @@ func (interp *Interpreter) Cfg(root *Node) ([]*Node, error) { case ValueT: n.typ = &Type{cat: ValueT, rtype: t.rtype.Elem()} case StringT: - n.typ = t + n.typ = scope.getType("byte") default: n.typ = t.val }