cgen: fix variadic sumtype args passing (fix #24150) (#24207)

This commit is contained in:
Felipe Pena 2025-04-14 05:01:18 -03:00 committed by GitHub
parent 880a9873a4
commit df1ec9135a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View File

@ -2522,8 +2522,10 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
}
} else {
// passing variadic arg to another call which expects same array type
if args.len == 1 && args[arg_nr].typ.has_flag(.variadic)
&& args[arg_nr].typ == varg_type {
if args.len == 1
&& ((args[arg_nr].typ.has_flag(.variadic) && args[arg_nr].typ == varg_type)
|| (varg_type.has_flag(.variadic)
&& args[arg_nr].typ == varg_type.clear_flag(.variadic))) {
g.ref_or_deref_arg(args[arg_nr], arr_info.elem_type, node.language,
false)
} else {

View File

@ -0,0 +1,24 @@
type Animal = Dog | Cat
struct Dog {
name string
}
struct Cat {
name string
}
fn print_names(animals ...Animal) {
for animal in animals {
assert animal.name == 'Kitty'
}
}
fn test_main() {
cat := Cat{
name: 'Kitty'
}
mut animals := []Animal{}
animals << cat
print_names(animals)
}