mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
4e05e07b94
commit
0fa6f60fac
@ -847,7 +847,9 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
g.expr(node.left)
|
||||
}
|
||||
g.write('${dot}_object')
|
||||
if node.args.len > 0 {
|
||||
is_variadic := node.expected_arg_types.len > 0
|
||||
&& node.expected_arg_types[node.expected_arg_types.len - 1].has_flag(.variadic)
|
||||
if node.args.len > 0 || is_variadic {
|
||||
g.write(', ')
|
||||
g.call_args(node)
|
||||
}
|
||||
|
@ -40,3 +40,29 @@ fn check_animals(animals ...Animal) {
|
||||
assert animals[0] is Cat
|
||||
assert animals[1] is Dog
|
||||
}
|
||||
|
||||
// For issue: 16286 passing nothing to a variatic parameter on an interface method gives builder error
|
||||
interface Bar {
|
||||
get(...int) []int
|
||||
}
|
||||
|
||||
struct Baz {}
|
||||
|
||||
fn (b Baz) get(n ...int) []int {
|
||||
if n.len == 0 {
|
||||
return [-1]
|
||||
} else {
|
||||
return n
|
||||
}
|
||||
}
|
||||
|
||||
fn test_empty_args_call_interface_methods() {
|
||||
b := Baz{}
|
||||
assert b.get() == [-1]
|
||||
|
||||
b_values := Bar(Baz{})
|
||||
assert b_values.get(1, 2, 3) == [1, 2, 3]
|
||||
|
||||
b_empty := Bar(Baz{})
|
||||
assert b_empty.get() == [-1]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user