mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix type alias of fn with mut argument (#16974)
This commit is contained in:
parent
199db81b23
commit
7fd9b62b34
@ -804,9 +804,9 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
|
||||
types_only := p.tok.kind in [.amp, .ellipsis, .key_fn, .lsbr]
|
||||
|| (p.peek_tok.kind == .comma && (p.table.known_type(argname) || is_generic_type))
|
||||
|| p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar || p.fn_language == .c
|
||||
|| (p.tok.kind == .key_mut && (p.peek_token(2).kind == .comma
|
||||
|| p.peek_token(2).kind == .rpar || (p.peek_tok.kind == .name
|
||||
&& p.peek_token(2).kind == .dot)))
|
||||
|| (p.tok.kind == .key_mut && (p.peek_tok.kind in [.amp, .ellipsis, .key_fn, .lsbr]
|
||||
|| p.peek_token(2).kind == .comma || p.peek_token(2).kind == .rpar
|
||||
|| (p.peek_tok.kind == .name && p.peek_token(2).kind == .dot)))
|
||||
// TODO copy paste, merge 2 branches
|
||||
if types_only {
|
||||
mut arg_no := 1
|
||||
|
13
vlib/v/tests/type_alias_of_fn_with_mut_args_test.v
Normal file
13
vlib/v/tests/type_alias_of_fn_with_mut_args_test.v
Normal file
@ -0,0 +1,13 @@
|
||||
type MutCallback = fn (mut []string)
|
||||
|
||||
fn mutate(mut ss []string, cb MutCallback) {
|
||||
cb(mut ss)
|
||||
}
|
||||
|
||||
fn test_type_alias_of_fn_with_mut_args() {
|
||||
mut s := ['a']
|
||||
mutate(mut s, fn (mut ss []string) {
|
||||
ss << 'b'
|
||||
})
|
||||
assert s == ['a', 'b']
|
||||
}
|
Loading…
Reference in New Issue
Block a user