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

parser: fix interface functions with no params (ui examples)

This commit is contained in:
Delyan Angelov 2020-06-29 10:53:12 +03:00
parent b6e6cde3e8
commit 1ba5996404
4 changed files with 32 additions and 3 deletions

View File

@ -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')

View File

@ -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
| ~~~~~~~~~~~~

View File

@ -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

View File

@ -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() {