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

Forbid local variables with same name as one of the imported modules #17173

Closed
2 tasks
i582 opened this issue Jan 31, 2023 · 0 comments · Fixed by #17197
Closed
2 tasks

Forbid local variables with same name as one of the imported modules #17173

i582 opened this issue Jan 31, 2023 · 0 comments · Fixed by #17197
Labels
Feature Request This issue is made to request a feature.

Comments

@i582
Copy link
Contributor

i582 commented Jan 31, 2023

Describe the feature

From doc:

You can shadow imported modules though, as it is very useful in some situations:

import ui
import gg

fn draw(ctx &gg.Context) {
	gg := ctx.parent.get_ui().gg
	gg.draw_rect(10, 10, 100, 50)
}

In the meantime, shadowing of variables is prohibited.

Shadowing the module name introduces ambiguity into the language for the reader. If I see that the gg module is imported, I can't be sure that gg.x() is a call to the x() function of the gg module. In the documentation example, this would be a struct method.

I don't see any big advantages in such shadowing, while the cons described above is quite big.

Use Case

See above

Proposed Solution

Forbid local variables with same name as one of the imported modules.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Version used

V 0.3.3 21b17fe.d563739

Environment details (OS name and version, etc.)

OS: macos, macOS, 13.0.1, 22A400
Processor: 10 cpus, 64bit, little endian, Apple M1 Pro
CC version: Apple clang version 14.0.0 (clang-1400.0.29.202)

getwd: /Users/petrmakhnev
vmodules: /Users/petrmakhnev/.vmodules
vroot: /Users/petrmakhnev/v
vexe: /Users/petrmakhnev/v/v
vexe mtime: 2023-01-31 09:57:40
is vroot writable: true
is vmodules writable: true
V full version: V 0.3.3 21b17fe.d563739

Git version: git version 2.37.1 (Apple Git-137.1)
Git vroot status: weekly.2023.04-39-gd5637392
.git/config present: true
thirdparty/tcc status: pmakhnev/fix_operator_overloading_doc 173c526e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is made to request a feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant