-
-
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] Conflict between Variable Name and Type in Unresolvable Scope #92008
Comments
I don't think this is possible, since you can still call static functions that exist on the types (not sure if Godot currently has any?). And for the "x is y" operator, it would be ambiguous if variables could in the future store types as values. Also for classes, it wouldn't work due to static functions and methods like .new() |
@RedMser To clarify, please see the following example: const Apple = preload("res://apple.gd")
func my_func() :
var my_var: Apple
var Apple = "pineapple"
print(Apple) The |
A local constant can be used as a type hint if it contains a preloaded class or enum. So while we don't support types as first-class citizens, types share the same scope as variables, constants, functions, etc. So if you declare a local identifier, then you can no longer use the same name class or global identifier, no matter what it is: a variable, a type, etc. The only bug here is that a constant declared after use should not shadow the identifier, only produce a warning. We fixed a similar bug in #79880, I'll look at that later for types. Also note that we recommend using |
Tested versions
v4.2.1.stable.official [b09f793]
v4.2.2.stable.official [15073af]
System information
N/A
Issue description
When declaring a variable with the syntax
var a: TypeName
followed byvar TypeName
in Godot Engine, an error is raised stating "Local variable 'TypeName' cannot be used as a type." This issue arises due to an unresolvable scope conflict where the engine cannot distinguish betweenTypeName
as both a type and a variable.Example Code:
Error Message:
The engine should either:
Also,
Steps to reproduce
Minimal reproduction project (MRP)
N/A
The text was updated successfully, but these errors were encountered: