-
-
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
Accessing a member variable before declaring a variable that would overshadow returns null #54944
Comments
It looks like local variable declarations affect the whole function/block. That is, your code is actually: func test():
print("in test")
func _ready():
var test # (It happens implicitly.)
print("_ready:")
print(test)
print(typeof(test))
test = 12 Probably, the compiler should print an error/warning "Using a local variable before its declaration". Use |
There is already a warning about shadowing method/variable names (the example code here shows one too), so the solution is to not use conflicting names, |
@dalexeev
Output:
it's ERROR!!! |
With #79880 this will work as expected, but will generate warnings. func test():
pass
func _ready():
print(test) # Node(node.gd)::test
print(typeof(test)) # 25
var test = 12
print(test) # 12
print(typeof(test)) # 2 |
Godot version
4.0-dev.20211108
System information
Ubuntu20.04,headless,HD Graphics 530
Issue description
I'm using Callable in Godot4.The following code works well:
output:
But when I write this:
Output:
Similarly, when I get a function with the same name before a variable declaration, I get null
Is it working properly?
If my grammar is OK,Why do I get null instead of Callable?
Is my grammar wrong? Godot4 doesn't have any reminders!
Steps to reproduce
run this in 4.0.dev
Minimal reproduction project
No response
Production team edit: added highlighting
The text was updated successfully, but these errors were encountered: