fix: range over strings (#216)
This commit is contained in:
committed by
Ludovic Fernandez
parent
e53548f4f2
commit
89171fe0cf
14
_test/str1.go
Normal file
14
_test/str1.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
func main() {
|
||||
for i, r := range itoa64 {
|
||||
if r == '1' {
|
||||
println(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// 3
|
||||
12
_test/str2.go
Normal file
12
_test/str2.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
const itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
|
||||
func main() {
|
||||
if itoa64[3] == '1' {
|
||||
println("ok")
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// ok
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user