1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix compiler error when match returns reference (#18728) (#18783)

This commit is contained in:
shove 2023-07-06 04:28:58 +08:00 committed by GitHub
parent 072364fc59
commit cd6330e218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -240,7 +240,8 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
&& (((ast.builtin_type_names_matcher.matches(p.tok.lit) || p.tok.lit[0].is_capital()) && (((ast.builtin_type_names_matcher.matches(p.tok.lit) || p.tok.lit[0].is_capital())
&& p.peek_tok.kind != .lpar) || (p.peek_tok.kind == .dot && p.peek_token(2).lit.len > 0 && p.peek_tok.kind != .lpar) || (p.peek_tok.kind == .dot && p.peek_token(2).lit.len > 0
&& p.peek_token(2).lit[0].is_capital()))) || p.is_only_array_type() && p.peek_token(2).lit[0].is_capital()))) || p.is_only_array_type()
|| p.tok.kind == .key_fn || p.peek_token(2).kind == .amp { || p.tok.kind == .key_fn
|| (p.tok.kind == .lsbr && p.peek_token(2).kind == .amp) {
mut types := []ast.Type{} mut types := []ast.Type{}
for { for {
// Sum type match // Sum type match

View File

@ -0,0 +1,29 @@
struct Foo {}
fn test_assign_ref_from_match() {
var := match 0 {
0 {
&Foo{}
}
else {
unsafe { nil }
}
}
assert var != unsafe { nil }
}
fn return_ref_from_match() &Foo {
return match 0 {
0 {
&Foo{}
}
else {
unsafe { nil }
}
}
}
fn test_return_ref_from_match() {
var := return_ref_from_match()
assert var != unsafe { nil }
}