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

v.parser: fix if a == Abc{} { (#11092)

This commit is contained in:
yuyi 2021-08-07 23:05:22 +08:00 committed by GitHub
parent 94c321c80d
commit 1d3786ff1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -2147,6 +2147,10 @@ pub fn (mut p Parser) name_expr() ast.Expr {
return map_init
}
return p.struct_init(false) // short_syntax: false
} else if p.peek_tok.kind == .lcbr && p.inside_if && lit0_is_capital && !known_var
&& language == .v {
// if a == Foo{} {...}
return p.struct_init(false)
} else if p.peek_tok.kind == .dot && (lit0_is_capital && !known_var && language == .v) {
// T.name
if p.is_generic_name() {

View File

@ -0,0 +1,11 @@
struct Foo {
bar int
}
fn test_if_expr_with_struct_init() {
a := Foo{}
if a == Foo{} {
println(true)
assert true
}
}