diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 0ea5e45f75..cf49cec579 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -367,7 +367,8 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool, bool) { mut args := []table.Arg{} mut is_variadic := false // `int, int, string` (no names, just types) - types_only := p.tok.kind in [.amp, .ellipsis, .key_fn] || (p.peek_tok.kind in [.comma, .rpar] && p.table.known_type(p.tok.lit)) + types_only := p.tok.kind in [.amp, .ellipsis, .key_fn] || (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 { // p.warn('types only') diff --git a/vlib/v/parser/tests/fn_type_only_args_in_interfaces.out b/vlib/v/parser/tests/fn_type_only_args_in_interfaces.out new file mode 100755 index 0000000000..0ce9615bbf --- /dev/null +++ b/vlib/v/parser/tests/fn_type_only_args_in_interfaces.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/fn_type_only_args_in_interfaces.v:22:1: error: `syntax_error` evaluated but not used + 20 | } + 21 | + 22 | syntax_error + | ~~~~~~~~~~~~ diff --git a/vlib/v/parser/tests/fn_type_only_args_in_interfaces.vv b/vlib/v/parser/tests/fn_type_only_args_in_interfaces.vv new file mode 100644 index 0000000000..0a3e839660 --- /dev/null +++ b/vlib/v/parser/tests/fn_type_only_args_in_interfaces.vv @@ -0,0 +1,22 @@ + +struct Type1 {} +struct Type2 {} +struct Type3 {} + + +pub interface Widget1 { + init(Type1, Type2) +} + +pub interface Widget2 { + init(Type1) + draw(Type2, Type3) +} + +pub interface Widget3 { + fnoparams1() + fnoparams2() + draw(Type1, Type2) +} + +syntax_error diff --git a/vlib/v/parser/tests/fn_type_only_args_unknown_name.out b/vlib/v/parser/tests/fn_type_only_args_unknown_name.out index a91e79972b..f90443c8ef 100644 --- a/vlib/v/parser/tests/fn_type_only_args_unknown_name.out +++ b/vlib/v/parser/tests/fn_type_only_args_unknown_name.out @@ -1,5 +1,6 @@ -vlib/v/parser/tests/fn_type_only_args_unknown_name.v:1:16: error: unexpected `{`, expecting `,` +vlib/v/parser/tests/fn_type_only_args_unknown_name.v:2:1: error: functions with type only args can not have bodies 1 | fn test(param) { - | ^ 2 | } + | ^ 3 | + 4 | fn main() {