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

const name shadowing #22072

Closed
Eliyaan opened this issue Aug 18, 2024 · 3 comments · Fixed by #22108
Closed

const name shadowing #22072

Eliyaan opened this issue Aug 18, 2024 · 3 comments · Fixed by #22108
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@Eliyaan
Copy link
Contributor

Eliyaan commented Aug 18, 2024

Describe the bug

(I'm not sure if it's called like that)
This code is able to reuse the name of a constant on another unrelated variable, and it can cause some mistakes.

Reproduction Steps

const item = 24

fn main() {
        for i, item in ["abc", "def"] {
                println(item)
        }
}

Expected Behavior

An error telling me that item is already used.

Current Behavior

It just worked

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7

Environment details (OS name and version, etc.)

linux

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@Eliyaan Eliyaan added the Bug This tag is applied to issues which reports bugs. label Aug 18, 2024
@Delta456 Delta456 self-assigned this Aug 18, 2024
@Delta456
Copy link
Member

This code compiles successfully.

const item = 24

fn main() {
	item := 34
	println(item)
}

@JalonSolov
Copy link
Contributor

V doesn't allow shadowing of other things, so I agree that this is a bug that it allows shadowing of a const.

@larpon
Copy link
Contributor

larpon commented Aug 18, 2024

Good find @Eliyaan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants