Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
parser: fix generic fn with upper name type (#9460) (#9478)
  • Loading branch information
yuyi98 committed Mar 26, 2021
1 parent 3220ab7 commit 36cc488
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/parser/parser.v
Expand Up @@ -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 {
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`
Expand Down
18 changes: 18 additions & 0 deletions vlib/v/tests/generic_fn_upper_name_type_test.v
@@ -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{})
}

0 comments on commit 36cc488

Please sign in to comment.