1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix fn variadic with enum value (#15177)

This commit is contained in:
yuyi 2022-07-22 21:08:22 +08:00 committed by GitHub
parent 092f5f0bf8
commit b0c32e0dbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -838,7 +838,15 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
c.error('too many arguments in call to `$func.name`', node.pos)
}
}
c.expected_type = param.typ
if func.is_variadic && i >= func.params.len - 1 {
param_sym := c.table.sym(param.typ)
if param_sym.kind == .array {
info := param_sym.array_info()
c.expected_type = info.elem_type
}
} else {
c.expected_type = param.typ
}
e_sym := c.table.sym(c.expected_type)
if call_arg.expr is ast.MapInit && e_sym.kind == .struct_ {

View File

@ -0,0 +1,19 @@
enum Foo {
a
b
c
}
fn foo(n int, m ...map[Foo]int) {
println(m)
assert m.len == 2
assert '$m' == '[{a: 1}, {b: 2}]'
}
fn test_vargs_with_enum_value() {
foo(1, {
.a: 1,
}, {
.b: 2,
})
}