diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index bcceb1d039..72aa49c283 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1121,15 +1121,20 @@ fn (p &Parser) is_generic_call() bool { } else { false } + tok2 := p.peek_token(2) + tok3 := p.peek_token(3) + tok4 := p.peek_token(4) + tok5 := p.peek_token(5) // use heuristics to detect `func()` from `var < expr` - return !lit0_is_capital && p.peek_tok.kind == .lt && (match p.peek_token(2).kind { + return !lit0_is_capital && p.peek_tok.kind == .lt && (match tok2.kind { .name { - // maybe `f`, `f`, `f`, ``, assume `var < []` is invalid - p.peek_token(3).kind == .rsbr + tok3.kind == .rsbr } else { false diff --git a/vlib/v/tests/generics_test.v b/vlib/v/tests/generics_test.v index 153e0033b5..21e3d3314d 100644 --- a/vlib/v/tests/generics_test.v +++ b/vlib/v/tests/generics_test.v @@ -23,6 +23,8 @@ fn test_identity() { assert simple<[]int>([1])[0] == 1 assert simple({'a':'b'})['a'] == 'b' + + assert simple(simplemodule.Data{value: 0}).value == 0 } fn test_plus() { diff --git a/vlib/v/tests/modules/simplemodule/simplemodule.v b/vlib/v/tests/modules/simplemodule/simplemodule.v index 6d3b19a5d7..31398309b1 100644 --- a/vlib/v/tests/modules/simplemodule/simplemodule.v +++ b/vlib/v/tests/modules/simplemodule/simplemodule.v @@ -10,4 +10,9 @@ pub fn imul(x int, y int) int { pub struct ThisIsGeneric { msg T -} +} + +pub struct Data { +pub: + value int +}