parser: fix interface functions with no params (ui examples)
parent
b6e6cde3e8
commit
1ba5996404
|
@ -367,7 +367,8 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool, bool) {
|
||||||
mut args := []table.Arg{}
|
mut args := []table.Arg{}
|
||||||
mut is_variadic := false
|
mut is_variadic := false
|
||||||
// `int, int, string` (no names, just types)
|
// `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
|
// TODO copy pasta, merge 2 branches
|
||||||
if types_only {
|
if types_only {
|
||||||
// p.warn('types only')
|
// p.warn('types only')
|
||||||
|
|
|
@ -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
|
||||||
|
| ~~~~~~~~~~~~
|
|
@ -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) {
|
1 | fn test(param) {
|
||||||
| ^
|
|
||||||
2 | }
|
2 | }
|
||||||
|
| ^
|
||||||
3 |
|
3 |
|
||||||
|
4 | fn main() {
|
||||||
|
|
Loading…
Reference in New Issue