mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix match expr case with struct init (#14538)
This commit is contained in:
parent
f3e7f24ee6
commit
a971b9a99a
@ -2381,9 +2381,10 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
|||||||
&& !p.inside_match_case && (!p.inside_if || p.inside_select)
|
&& !p.inside_match_case && (!p.inside_if || p.inside_select)
|
||||||
&& (!p.inside_for || p.inside_select) && !known_var {
|
&& (!p.inside_for || p.inside_select) && !known_var {
|
||||||
return p.struct_init(p.mod + '.' + p.tok.lit, false) // short_syntax: false
|
return p.struct_init(p.mod + '.' + p.tok.lit, false) // short_syntax: false
|
||||||
} else if p.peek_tok.kind == .lcbr && p.inside_if && lit0_is_capital && !known_var
|
} else if p.peek_tok.kind == .lcbr
|
||||||
&& language == .v {
|
&& ((p.inside_if && lit0_is_capital && !known_var && language == .v)
|
||||||
// if a == Foo{} {...}
|
|| (p.inside_match_case && p.tok.kind == .name && p.peek_tok.pos - p.tok.pos == p.tok.len)) {
|
||||||
|
// `if a == Foo{} {...}` or `match foo { Foo{} {...} }`
|
||||||
return p.struct_init(p.mod + '.' + p.tok.lit, false)
|
return p.struct_init(p.mod + '.' + p.tok.lit, false)
|
||||||
} else if p.peek_tok.kind == .dot && (lit0_is_capital && !known_var && language == .v) {
|
} else if p.peek_tok.kind == .dot && (lit0_is_capital && !known_var && language == .v) {
|
||||||
// T.name
|
// T.name
|
||||||
|
29
vlib/v/tests/match_case_with_struct_init_test.v
Normal file
29
vlib/v/tests/match_case_with_struct_init_test.v
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
struct Get {}
|
||||||
|
|
||||||
|
struct Post {}
|
||||||
|
|
||||||
|
struct Part {
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
|
type RoutePart = Get | Part | Post
|
||||||
|
|
||||||
|
fn test_match_case_with_struct_init() {
|
||||||
|
route := [RoutePart(Get{}), RoutePart(Part{
|
||||||
|
value: '/'
|
||||||
|
})]
|
||||||
|
|
||||||
|
status_code := match route {
|
||||||
|
[RoutePart(Get{}), RoutePart(Part{
|
||||||
|
value: '/'
|
||||||
|
})] {
|
||||||
|
'200'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
'404'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print(status_code)
|
||||||
|
assert status_code == '200'
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user