-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
GDScript: Fix bug with identifier shadowed below in current scope #79880
GDScript: Fix bug with identifier shadowed below in current scope #79880
Conversation
bbf7c68
to
198ffad
Compare
198ffad
to
5a177d7
Compare
5a177d7
to
12d93e5
Compare
12d93e5
to
d53fc92
Compare
Ready for review. Test project: gdscript-test-scopes-4.x.zip Notes: 1. I'm not sure about the warning identifiers 2. The word "below" in the warning text is ok? In the case of
3. The var a = 1
func test():
print(a) # Warning CONFUSABLE_LOCAL_USAGE.
var a = 2
print(a) If you nest this inside another block, there will be no warning: var a = 1
func test():
print(a) # No warning.
if true:
var a = 2
print(a) Is this OK or should we also check all nested blocks recursively? I don't think it's worth it. Also, a naive implementation can have a negative performance impact for large scripts. 4. I think the for i in 3: # <-- CONFUSABLE_LOCAL_DECLARATION?
print(i)
var i = 2 5. I didn't find any errors, even this case now give correct autocompletion: var a := Color.RED
func f(a: String = a.to_html(), b = a.begins_with("#")):
prints(a, b) But please test too. Don't forget about possible regressions elsewhere. |
Tech note
The order in which the identifier source is resolved:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed in the GDScript meeting. It has been approved! Thanks @dalexeev for your PR and your work.
Thanks! |
One issue I have with this is lambda functions: any variable declared inside the lambda function can raise a warning about confusable local declaration if code below the function declares a variable with the same name. var my_func := func my_func() -> int:
var problem := 0
return problem
var problem := my_func.call() as int The variable The second example below is a bit different and probably has to do with bad practice: I assume it is intended behavior to raise a warning here for for i in 10:
var another_problem := i
print(another_problem)
@warning_ignore("unused_variable")
var another_problem := 0 |
Lambdas capture identities from outer scope, so I think the warning is valid.
This is a bug. |
var a = a + 1
).