-
-
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 2.0] Constant array/dictionary inconsistency #62680
Comments
From what I can tell and some minor testing it would be here: godot/modules/gdscript/gdscript_analyzer.cpp Line 3275 in 90c33ed
With the first clause making a constant base with constant index/key a constant expression (thus folding it to the actual value) but the subsequent clause ignores any constness of the base type |
I believe adding a simple fix solves this but I don't know if I'm well versed enough in the inner workings of GDScript to handle such a PR |
I think it wouldn't be easy to do this currently, but since read-only Array/Dictionary was introduced recently (#61127) it'll probably be possible in GDScript soon. Actually, checking usage like above can be done before that, but currently |
This is true! But I think this check needs to be kept in mind when/if implementing read-only arrays/dictionaries in GDScript And read-only isn't necessarily required for this, nor would it necessarily solve it from my reading of the read-only code in dict/array as it doesn't enforce anything, it only seems to fail silently (i.e. allow writes to the value but not update the original value), so the error would be needed to indicate this and prevent compilation I feel |
Godot version
90c33ed
System information
Windows 10
Issue description
Accessing constant arrays and dictionaries with index/key from a variable does not trigger an error:
It appears to be caused by a failure to set the type of such a subscript to constant, where as the case with a literal is folded into a constant expression (which isn't possible for a variable as the index/key is not known at compile time)
Steps to reproduce
See above
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: