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:
parent
b6e6cde3e8
commit
1ba5996404
@ -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')
|
||||
|
5
vlib/v/parser/tests/fn_type_only_args_in_interfaces.out
Executable file
5
vlib/v/parser/tests/fn_type_only_args_in_interfaces.out
Executable 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
|
||||
| ~~~~~~~~~~~~
|
22
vlib/v/parser/tests/fn_type_only_args_in_interfaces.vv
Normal file
22
vlib/v/parser/tests/fn_type_only_args_in_interfaces.vv
Normal 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
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user