fix: handle index expression on binary string type

This commit is contained in:
Marc Vertes
2019-11-19 15:06:05 +01:00
committed by Traefiker Bot
parent 08a37fc4bf
commit 56bec974e1
2 changed files with 16 additions and 1 deletions

11
_test/str3.go Normal file
View File

@@ -0,0 +1,11 @@
package main
import "strconv"
func main() {
str := strconv.Itoa(101)
println(str[0] == '1')
}
// Output:
// true

View File

@@ -634,7 +634,11 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
case stringT:
n.typ = sc.getType("byte")
case valueT:
n.typ = &itype{cat: valueT, rtype: t.rtype.Elem()}
if t.rtype.Kind() == reflect.String {
n.typ = sc.getType("byte")
} else {
n.typ = &itype{cat: valueT, rtype: t.rtype.Elem()}
}
default:
n.typ = t.val
}