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:
parent
092f5f0bf8
commit
b0c32e0dbf
@ -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)
|
||||
}
|
||||
}
|
||||
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_ {
|
||||
|
19
vlib/v/tests/vargs_with_enum_value_test.v
Normal file
19
vlib/v/tests/vargs_with_enum_value_test.v
Normal 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,
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user