From bb39b59767d78e9aed524d8cf87b35f19cc97eee Mon Sep 17 00:00:00 2001 From: kbkpbot Date: Thu, 18 Dec 2025 14:51:53 +0800 Subject: [PATCH] scanner: remove old generic check logic (fix #25959) (#25997) --- vlib/v/scanner/scanner.v | 25 ++++--------------------- vlib/v/tests/old_generic_scanner_test.v | 11 +++++++++++ 2 files changed, 15 insertions(+), 21 deletions(-) create mode 100644 vlib/v/tests/old_generic_scanner_test.v diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 87309fd04..83e8c1658 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -9,7 +9,9 @@ import v.token import v.pref import v.util import v.errors -import v.ast + +@[markused] +const workaround_markused_bug = map[string]int{} const single_quote = `'` const double_quote = `"` @@ -963,26 +965,7 @@ pub fn (mut s Scanner) text_scan() token.Token { return s.new_token(.ge, '', 2) } else if nextc == `>` { if s.pos + 2 < s.text.len { - // an algorithm to decide it's generic or non-generic - // such as `foo>(a)` vs `a, b := Foo{}>(baz)` - // @SleepyRoy if you have smarter algorithm :-) - // almost correct heuristics: last of generic cannot be extremely long - // here we set the limit 100 which should be nice for real cases - // e.g. ...Bar, Baz_, [20]f64, map[string][]bool>> => - // int, Baz_, f64, bool - is_generic := if s.last_lt >= 0 && s.pos - s.last_lt < 100 { - typs := s.text[s.last_lt + 1..s.pos].split(',').map(it.trim_space().trim_right('>').after(']')) - // if any typ is neither Type nor builtin, then the case is non-generic - typs.all(it.len > 0 - && ((it[0].is_capital() && it[1..].bytes().all(it.is_alnum() - || it == `_`)) - || ast.builtin_type_names_matcher.matches(it))) - } else { - false - } - if is_generic { - return s.new_token(.gt, '', 1) - } else if s.text[s.pos + 2] == `=` { + if s.text[s.pos + 2] == `=` { s.pos += 2 return s.new_token(.right_shift_assign, '', 3) } else if s.text[s.pos + 2] == `>` { diff --git a/vlib/v/tests/old_generic_scanner_test.v b/vlib/v/tests/old_generic_scanner_test.v new file mode 100644 index 000000000..79961ccdf --- /dev/null +++ b/vlib/v/tests/old_generic_scanner_test.v @@ -0,0 +1,11 @@ +module main + +fn test_main() { + p := 100 + for i := 0; i < 4; i += 4 { + // keep following comment: + // p := unsafe {pixels[i]} + r := u8(p >> 24) + assert r == 0 + } +} -- 2.39.5