orm: cgen bug fix (fixes #25847)
This commit is contained in:
1 parent
ad9d9125f8
commit
38ac4e6dba
3 files changed
+57
-3
No files matched your search
+3
-1
@@ -363,7 +363,9 @@ pub fn (qb_ &QueryBuilder[T]) set(assign string, values ...Primitive) !&QueryBui
|
||||
fields << field
|
||||
}
|
||||
qb.data.fields << fields
|
||||
qb.data.data << values
|
||||
for v in values {
|
||||
qb.data.data << v
|
||||
}
|
||||
return qb
|
||||
}
|
||||
|
||||
|
||||
@@ -1055,8 +1055,8 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
|
||||
if (right.unaliased_sym.kind == .array
|
||||
|| (right.unaliased_sym.kind == .struct && right.unaliased_sym.name == 'array'))
|
||||
&& left.sym.nr_dims() == right.sym.nr_dims() && array_info.elem_type != right.typ
|
||||
&& !elem_is_option && !(right.sym.kind == .alias
|
||||
&& g.table.sumtype_has_variant(array_info.elem_type, node.right_type, false)) {
|
||||
&& !elem_is_option
|
||||
&& !g.table.sumtype_has_variant(array_info.elem_type, node.right_type, false) {
|
||||
// push an array => PUSH_MANY, but not if pushing an array to 2d array (`[][]int << []int`)
|
||||
g.write('_PUSH_MANY${noscan}(')
|
||||
mut expected_push_many_atype := left.typ
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// vtest flance: -d MOREINFO
|
||||
// Test for issue #25847: C error with sumtype arrays
|
||||
// Bug: When pushing an array to []SumType where SumType has []SumType as a variant,
|
||||
// the compiler incorrectly used PUSH_MANY instead of pushing as a single element.
|
||||
|
||||
type Prim = int | string | []Prim
|
||||
|
||||
fn test_push_array_literal_to_sumtype_array() {
|
||||
mut args := []Prim{}
|
||||
// Push an array literal as a single element (it should become a Prim variant)
|
||||
args << [Prim(1), Prim(2)]
|
||||
assert args.len == 1
|
||||
|
||||
inner := args[0] as []Prim
|
||||
assert inner.len == 2
|
||||
assert (inner[0] as int) == 1
|
||||
assert (inner[1] as int) == 2
|
||||
}
|
||||
|
||||
fn test_push_array_variable_to_sumtype_array() {
|
||||
mut args := []Prim{}
|
||||
// Push an array variable as a single Prim element
|
||||
nested := []Prim{len: 2, init: Prim(index)}
|
||||
args << nested
|
||||
assert args.len == 1
|
||||
|
||||
inner := args[0] as []Prim
|
||||
assert inner.len == 2
|
||||
}
|
||||
|
||||
fn test_push_single_elements_still_works() {
|
||||
mut args := []Prim{}
|
||||
// Push single elements (not arrays)
|
||||
args << 42
|
||||
args << 'hello'
|
||||
args << 123
|
||||
assert args.len == 3
|
||||
|
||||
assert (args[0] as int) == 42
|
||||
assert (args[1] as string) == 'hello'
|
||||
assert (args[2] as int) == 123
|
||||
}
|
||||
|
||||
fn test_empty_sumtype_array_init() {
|
||||
mut args := []Prim{}
|
||||
assert args.len == 0
|
||||
|
||||
for i in 0 .. 3 {
|
||||
args << i
|
||||
}
|
||||
assert args.len == 3
|
||||
}
|
||||
Reference in new issue
Block a user