parser: fix generic fn with upper name type (#9460) (#9478)

pull/9483/head
yuyi 2021-03-26 22:50:35 +08:00 committed by GitHub
parent 3220ab7053
commit 36cc4880a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -1710,7 +1710,7 @@ pub fn (mut p Parser) parse_ident(language table.Language) ast.Ident {
} }
fn (p &Parser) is_typename(t token.Token) bool { fn (p &Parser) is_typename(t token.Token) bool {
return t.kind == .name && (t.lit.is_capital() || p.table.known_type(t.lit)) return t.kind == .name && (t.lit[0].is_capital() || p.table.known_type(t.lit))
} }
// heuristics to detect `func<T>()` from `var < expr` // heuristics to detect `func<T>()` from `var < expr`

View File

@ -0,0 +1,18 @@
struct XX {
x int
}
struct YY {
y int
}
fn show_result<T, U>(x T, y U) bool {
return true
}
fn test_generic_fn_upper_name_type() {
assert show_result<int, bool>(1, false)
assert show_result<string, XX>( "s", XX{})
assert show_result< XX, string>(XX{}, "s")
assert show_result< XX, YY>(XX{}, YY{})
}