Skip to content

Commit

Permalink
parser: fix for comptime with fully type name (fix vlang#20948) (vlan…
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored Mar 9, 2024
1 parent da62854 commit e3140cb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vlib/v/parser/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor {
mut typ_pos := p.tok.pos()
lang := p.parse_language()
mut typ := ast.void_type
if p.tok.lit[0].is_capital() {
typ = p.parse_any_type(lang, false, false, false)
if p.tok.lit[0].is_capital() || p.tok.lit in p.imports {
typ = p.parse_any_type(lang, false, true, false)
} else {
expr = p.ident(lang)
p.mark_var_as_used((expr as ast.Ident).name)
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/parser/parse_type.v
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_dot b
for p.peek_tok.kind == .dot {
mod_pos = mod_pos.extend(p.tok.pos())
mod_last_part = p.tok.lit
if p.tok.lit[0].is_capital() {
// it's a type name, should break loop
break
}
mod += '.${mod_last_part}'
p.next()
p.check(.dot)
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/tests/comptime_for_mod_name_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import net.http

fn test_main() {
mut count := 0
$for method_val in http.Method.values {
println(method_val.name)
count++
}
assert count > 0
}

0 comments on commit e3140cb

Please sign in to comment.