Skip to content

Commit 40e86a7

Browse files
authored
wasm: fix string plus assign with call expr (#26287)
1 parent d66e4b6 commit 40e86a7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

vlib/v/gen/wasm/gen.v

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,9 +1365,13 @@ pub fn (mut g Gen) expr_stmt(node ast.Stmt, expected ast.Type) {
13651365
}
13661366
}
13671367

1368-
if !passed && node.op == .assign {
1369-
if v := g.get_var_from_expr(left) {
1370-
var = v
1368+
if !passed {
1369+
if node.op == .assign {
1370+
if v := g.get_var_from_expr(left) {
1371+
var = v
1372+
}
1373+
} else if node.op == .plus_assign && g.is_param_type(rt) {
1374+
var = g.new_local('', rt)
13711375
}
13721376
}
13731377

vlib/v/gen/wasm/tests/builtin.vv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ fn str_implicit() {
118118
println(a + 10)
119119
}
120120

121+
fn str_plus_assign_with_call_expr() {
122+
mut str := 'a'
123+
str += 1.str()
124+
println(str)
125+
}
126+
121127
fn assertions() {
122128
assert true, 'hello'
123129
assert true
@@ -133,6 +139,7 @@ fn main() {
133139
str_cmp()
134140
str_loop_concat()
135141
str_literal()
142+
str_plus_assign_with_call_expr()
136143
assertions()
137144

138145
// panic('nooo!')

vlib/v/gen/wasm/tests/builtin.vv.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Such wow
4343
Helllo!
4444
42
4545
0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10!
46+
a1
4647
wasm builtins
4748
1
48-
1
49+
1

0 commit comments

Comments
 (0)