1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

bare: fix str[idx]

This commit is contained in:
Alexander Medvednikov
2019-11-16 23:22:40 +03:00
parent 0c5854e371
commit 5a1de13e10
3 changed files with 12 additions and 6 deletions

View File

@ -211,8 +211,11 @@ fn (p mut Parser) index_get(typ string, fn_ph int, cfg IndexConfig) {
}
}
}
else if cfg.is_str && !p.builtin_mod && !p.pref.is_bare {
if cfg.is_slice {
else if cfg.is_str && !p.builtin_mod {
if p.pref.is_bare {
p.gen(index_expr)
}
else if cfg.is_slice {
p.gen('string_substr2($index_expr)')
} else {
p.gen('string_at($index_expr)')

View File

@ -1856,10 +1856,10 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
if is_str {
typ = 'byte'
// Direct faster access to .str[i] in builtin modules
if p.builtin_mod {
if p.builtin_mod || p.pref.is_bare {
p.gen('.str[')
close_bracket = true
}
}
else {
// Bounds check everywhere else
p.gen(', ')