cgen: properly cast to sumtypes in array prepend and insert (#11289)
parent
4824b409b1
commit
3249f8f0e7
|
@ -411,7 +411,7 @@ fn (mut g Gen) gen_array_insert(node ast.CallExpr) {
|
||||||
if left_info.elem_type == ast.string_type {
|
if left_info.elem_type == ast.string_type {
|
||||||
g.write('string_clone(')
|
g.write('string_clone(')
|
||||||
}
|
}
|
||||||
g.expr(node.args[1].expr)
|
g.expr_with_cast(node.args[1].expr, node.args[1].typ, left_info.elem_type)
|
||||||
if left_info.elem_type == ast.string_type {
|
if left_info.elem_type == ast.string_type {
|
||||||
g.write(')')
|
g.write(')')
|
||||||
}
|
}
|
||||||
|
@ -441,7 +441,7 @@ fn (mut g Gen) gen_array_prepend(node ast.CallExpr) {
|
||||||
g.write('.len)')
|
g.write('.len)')
|
||||||
} else {
|
} else {
|
||||||
g.write(', &($elem_type_str[]){')
|
g.write(', &($elem_type_str[]){')
|
||||||
g.expr(node.args[0].expr)
|
g.expr_with_cast(node.args[0].expr, node.args[0].typ, left_info.elem_type)
|
||||||
g.write('})')
|
g.write('})')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
struct Node {
|
||||||
|
mut:
|
||||||
|
tag string
|
||||||
|
content []Content
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Text {
|
||||||
|
}
|
||||||
|
|
||||||
|
type Content = Node | Text
|
||||||
|
|
||||||
|
fn test_push_prepend_insert() {
|
||||||
|
mut body := Node{}
|
||||||
|
body.content << Node{
|
||||||
|
tag: 'a'
|
||||||
|
}
|
||||||
|
body.content.prepend(Node{ tag: 'b' })
|
||||||
|
body.content.insert(1, Node{ tag: 'c' })
|
||||||
|
assert body.content.len == 3
|
||||||
|
}
|
Loading…
Reference in New Issue