From 30f1c6bad5e6c45397c4070d3c701b97aa5839e4 Mon Sep 17 00:00:00 2001 From: spaceface777 Date: Mon, 8 Jun 2020 19:02:36 +0200 Subject: [PATCH] parser: fix type_only fns starting with varargs --- vlib/v/parser/fn.v | 2 +- vlib/v/tests/interop_test.v | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/interop_test.v diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 0ac9b2109c..5423a042f8 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -359,7 +359,7 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) { mut args := []table.Arg{} mut is_variadic := false // `int, int, string` (no names, just types) - types_only := p.tok.kind in [.amp, .and] || (p.peek_tok.kind == .comma && p.table.known_type(p.tok.lit)) || + types_only := p.tok.kind in [.amp, .and, .ellipsis] || (p.peek_tok.kind == .comma && p.table.known_type(p.tok.lit)) || p.peek_tok.kind == .rpar // TODO copy pasta, merge 2 branches if types_only { diff --git a/vlib/v/tests/interop_test.v b/vlib/v/tests/interop_test.v new file mode 100644 index 0000000000..6d13d872be --- /dev/null +++ b/vlib/v/tests/interop_test.v @@ -0,0 +1,16 @@ +// Not real external functions, so we won't call them +// We just want to make sure they compile + +struct Foo {} + +fn C.a(a string, b int) f32 +fn C.b(a &voidptr) +fn C.c(a string, b ...string) string +fn C.d(a ...int) + +fn JS.e(a string, b ...string) int +fn JS.f(a &Foo) // TODO: Should this be allowed? + +fn C.g(string, ...int) +fn C.h(&int) +fn JS.i(...string)