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:
@@ -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]
|
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 == .comma && (p.table.known_type(argname) || is_generic_type))
|
||||||
|| p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar || p.fn_language == .c
|
|| 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.tok.kind == .key_mut && (p.peek_tok.kind in [.amp, .ellipsis, .key_fn, .lsbr]
|
||||||
|| p.peek_token(2).kind == .rpar || (p.peek_tok.kind == .name
|
|| p.peek_token(2).kind == .comma || p.peek_token(2).kind == .rpar
|
||||||
&& p.peek_token(2).kind == .dot)))
|
|| (p.peek_tok.kind == .name && p.peek_token(2).kind == .dot)))
|
||||||
// TODO copy paste, merge 2 branches
|
// TODO copy paste, merge 2 branches
|
||||||
if types_only {
|
if types_only {
|
||||||
mut arg_no := 1
|
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']
|
||||||
|
}
|
Reference in New Issue
Block a user