cgen: fix string range index in for mut var in (#13076)

pull/13080/head
yuyi 2022-01-07 19:00:48 +08:00 committed by GitHub
parent 5bc72c9c01
commit c9d8fecc75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -65,6 +65,9 @@ fn (mut g Gen) range_expr(node ast.IndexExpr, range ast.RangeExpr) {
} else { } else {
g.write('string_substr(') g.write('string_substr(')
} }
if node.left_type.is_ptr() {
g.write('*')
}
g.expr(node.left) g.expr(node.left)
} else if sym.kind == .array { } else if sym.kind == .array {
if node.is_gated { if node.is_gated {

View File

@ -0,0 +1,25 @@
module main
[heap]
pub struct Grid {
pub mut:
header []string
}
fn test_string_index_in_for_mut_in() {
h := ['yore', 'yaya']
mut grid := Grid{
header: h
}
wrap_text(mut grid)
}
fn wrap_text(mut gv Grid) {
for mut ch in gv.header {
ch = ch[1..2]
}
println(gv)
assert gv.header == ['o', 'a']
}