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

fmt: simplify const name formatting #21143

Merged
merged 1 commit into from
Mar 30, 2024
Merged
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
12 changes: 4 additions & 8 deletions vlib/v/fmt/fmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -2255,18 +2255,14 @@ pub fn (mut f Fmt) ident(node ast.Ident) {
// This makes it clear that a module const is being used
// (since V's consts are no longer ALL_CAP).
// ^^^ except for `main`, where consts are allowed to not have a `main.` prefix.
mod := f.cur_mod
full_name := mod + '.' + node.name
if obj := f.file.global_scope.find(full_name) {
if obj := f.file.global_scope.find('${f.cur_mod}.${node.name}') {
if obj is ast.ConstField {
// "v.fmt.foo" => "fmt.foo"
vals := full_name.split('.')
mod_prefix := vals[vals.len - 2]
const_name := vals.last()
if mod_prefix == 'main' {
const_name := node.name.all_after_last('.')
if f.cur_mod == 'main' {
f.write(const_name)
} else {
short := mod_prefix + '.' + const_name
short := '${f.cur_mod.all_after_last('.')}.${const_name}'
f.write(short)
f.mark_import_as_used(short)
}
Expand Down