Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: fix for comptime with fully type name #20988

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}