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

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

This commit is contained in:
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()
p.check(.rcbr) // `}`
} 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 {}
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()
}