v.parser: fix generics type name in if_expr (#11156)

pull/11160/head
yuyi 2021-08-12 15:19:06 +08:00 committed by GitHub
parent e089d66225
commit 89a8854e57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -57,7 +57,7 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
node = p.map_init() node = p.map_init()
p.check(.rcbr) // `}` p.check(.rcbr) // `}`
} else { } else {
if p.inside_if && p.is_generic_name() { if p.inside_if && p.is_generic_name() && p.peek_tok.kind != .dot {
// $if T is string {} // $if T is string {}
p.expecting_type = true p.expecting_type = true
} }

View File

@ -0,0 +1,13 @@
struct Flag<T> {}
fn (f Flag<T>) verify() {
if T.name == 'int' {
println('It is an int!')
assert true
}
}
fn test_generic_type_name_in_if() {
flag := Flag<int>{}
flag.verify()
}