1
0
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:
yuyi 2023-01-15 03:38:46 +08:00 committed by GitHub
parent 199db81b23
commit 7fd9b62b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

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

View 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']
}