checker: fix multi return using nil and voidptrfix (fix #17343) (#21144)

This commit is contained in:
Felipe Pena 2024-03-30 08:59:42 -03:00 committed by GitHub
parent 66e6140568
commit d5afce3171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -3878,7 +3878,12 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
fn (mut c Checker) concat_expr(mut node ast.ConcatExpr) ast.Type {
mut mr_types := []ast.Type{}
for mut expr in node.vals {
mr_types << c.expr(mut expr)
mut typ := c.expr(mut expr)
if typ == ast.nil_type {
// nil and voidptr produces the same struct type name
typ = ast.voidptr_type
}
mr_types << typ
}
if node.vals.len == 1 {
typ := mr_types[0]

View File

@ -0,0 +1,17 @@
fn ret_int_ptr(arg int) !(int, voidptr) {
if arg < 0 {
return error('argument is smaller then zero')
}
return 1, [1, 2, 3].data
}
fn test_main() {
mut val1 := 0
mut val2 := unsafe { nil }
val1, val2 = ret_int_ptr(-1) or {
println(err)
val1, val2
}
assert val1 == 0
assert val2 == unsafe { nil }
}