Variable can be redefined #15

Closed
opened 2025-08-17 17:34:03 +00:00 by zupa · 4 comments

A variable can be redefined in the same scope, with either the same or a different type.

Example:

import io

main() {
	s := "foo"
	_(s)
	s := "bar"
	io.write(s) // Writes "bar"
}

_(_ any) {}

I'm not saying that's bad but it was unexpected. I discovered this by having a bug: a function had an input named b, and I also created a variable named b, which resulted in unexpected behavior.

I'm reporting this as I assume this is unintended behavior, given how strict the language is with unused variables.

A variable can be redefined in the same scope, with either the same or a different type. Example: ``` import io main() { s := "foo" _(s) s := "bar" io.write(s) // Writes "bar" } _(_ any) {} ``` I'm not saying that's bad but it was unexpected. I discovered this by having a bug: a function had an input named `b`, and I also created a variable named `b`, which resulted in unexpected behavior. I'm reporting this as I assume this is unintended behavior, given how strict the language is with unused variables.
Author

After some reflection, I think this issue should most likely be ignored for now. There are far more pressing issues, plus this is a semantic issue not a backend issue.

If you agree, 1) please close this, and 2) I'll try to avoid reporting these issues in the future.

After some reflection, I think this issue should most likely be ignored for now. There are far more pressing issues, plus this is a semantic issue not a backend issue. If you agree, 1) please close this, and 2) I'll try to avoid reporting these issues in the future.
Owner

Definitely unintended. Fix coming soon.

Definitely unintended. Fix coming soon.
Owner

Fixed in cli/q@088b883c08.

No worries, these types of reports are very useful!
They are just as important as new feature development, if not more important.

Fixed in https://git.urbach.dev/cli/q/commit/088b883c089194dd0d4ce62577c7b32454ff4b4c. No worries, these types of reports are very useful! They are just as important as new feature development, if not more important.
ed added spent time 2025-08-17 18:01:09 +00:00
15 minutes
Author

Ok! Thx, closing.

Ok! Thx, closing.
zupa closed this issue 2025-08-17 20:31:26 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Total time spent: 15 minutes
ed
15 minutes
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cli/q#15
No description provided.