-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
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: Static typing on signals isn't enforced #54333
Comments
Duplicate of godotengine/godot-proposals#2557. |
I was aware of that issue, the weird part is that is accepts type arguments without complaint, it just doesn't use them. On 3.x you get an error if you try to add types to signal arguments. So if this won't be supported for 4.0 then the ability to add types to signal arguments should be removed. |
See also #52083 (comment). |
Okay, but at the very least this limitation should be documented before this issue is closed, otherwise it's quite counterintuitive as many users will expect the types to be enforced. |
@vnen I would push this issue to 4.x or 4.1 |
Bumping this as relatively important for the following reason: When checking the types for the argument list of a signal against those of the parameter list for a potential method that will connect. In this instance, for every built-in signal there are types, for custom signals the types are all '0'. |
There is no protection for built-in signals either, you can emit a signal with any arguments. The only "protection" is callback type hints. The difference from built-in signals is that the editor does not currently use this information when generating a custom signal callback. But this can be considered a bug that we need to fix. extends Node
func _ready() -> void:
child_entered_tree.connect(_on_child_entered_tree)
child_entered_tree.emit(42, [], NAN) # No error.
#func _on_child_entered_tree(node: Node) -> void:
# pass
func _on_child_entered_tree(a, b, c) -> void:
prints(a, b, c) |
BTW this isn't related to enforcing types on signals, this is only because script info is not being populated properly for all the |
Wanted to chime in with an example as to why this feature is important. I had the following code:
Can you spot the bug?
It's way too easy for minor type mistakes to lead to silent failures, and they're extremely annoying to debug. I haven't had to do any refactoring work around signals yet, but I'd bet my bottom dollar that it can be a similarly frustrating debugging experience. Calling |
So, this is not really a bug. It could be changed but it is like so by design because the core never enforced types either. The types you can set are only for documentation purposes, at least for now, the same as they are in core. |
Fixed in #79366 and others. |
Godot version
v4.0.dev.custom_build [a851012b1]
System information
Windows 10
Issue description
The following code:
compiles without any errors, and prints
(1, -1)
.It should produce an error, something like:
Steps to reproduce
See above.
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: