mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix array_init_with_default
This commit is contained in:
parent
48659f4145
commit
6855996cca
@ -979,7 +979,7 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
|
||||
has_val = it.has_val
|
||||
if it.has_default {
|
||||
elem_type_str := g.typ(it.elem_type)
|
||||
g.write('$elem_type_str ${elem_type_str}_val_t = ')
|
||||
g.write('$elem_type_str _val_$it.pos.pos = ')
|
||||
g.expr(it.default_expr)
|
||||
g.writeln(';')
|
||||
}
|
||||
@ -3862,7 +3862,7 @@ fn (mut g Gen) array_init(it ast.ArrayInit) {
|
||||
}
|
||||
g.write('sizeof($elem_type_str), ')
|
||||
if it.has_default {
|
||||
g.write('&${elem_type_str}_val_t)')
|
||||
g.write('&_val_$it.pos.pos)')
|
||||
} else {
|
||||
g.write('0)')
|
||||
}
|
||||
|
@ -16,9 +16,15 @@ fn test_array_init() {
|
||||
}
|
||||
|
||||
fn test_array_init_with_default() {
|
||||
a := []int{len: 4, init: 2}
|
||||
assert '$a' == '[2, 2, 2, 2]'
|
||||
a1 := []int{len: 4, init: 2}
|
||||
assert '$a1' == '[2, 2, 2, 2]'
|
||||
|
||||
b := []string{len: 3, init: 'abc'}
|
||||
assert '$b' == "['abc', 'abc', 'abc']"
|
||||
a2 := []int{len: 3, init: 12345}
|
||||
assert '$a2' == '[12345, 12345, 12345]'
|
||||
|
||||
b1 := []string{len: 3, init: 'abc'}
|
||||
assert '$b1' == "['abc', 'abc', 'abc']"
|
||||
|
||||
b2 := []string{len: 2, init: '111'}
|
||||
assert '$b2' == "['111', '111']"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user