-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
Core: Allow methods of built-in Variant
types to be used as Callables
#82264
Core: Allow methods of built-in Variant
types to be used as Callables
#82264
Conversation
7cad1b2
to
75e4f09
Compare
75e4f09
to
b042636
Compare
It makes sense to change the argument type in the constructor from |
This is quite important IMO, as currently there is no proper type safe way to do See #84046 (comment) for context, where currently a lambda needs to be used instead of doing BTW if this works in this PR, this could be worth adding as a unit test. |
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.
No apparent issues to me. TIWAGOS, though.
I found an issue with
Does not work with |
Thanks! |
Hi folks! I ran into this commit while working on GDScript Structs #82198 and worried there might be an issue with this feature and built in Variants with dynamic properties, that is, Dictionaries and eventually Structs (which are just fancy arrays). For example if I run var dict: Dictionary = {&"clear" : "oops"}
var callable: Callable = dict.clear The analyzer does not complain, but at runtime, I get "INTERNAL ERROR: Trying to assign value of type 'String' to a variable of type 'Callable'." At the moment, my Struct branch is failing the unit test that was added for this feature: var array: Array = [1, 2, 3]
print(array) # [1, 2, 3]
var callable: Callable = array.clear
callable.call()
print(array) # [] in the same way that the dictionary example I gave above fails as I have added named getters to arrays so that struct fields can be accessed like I'm not entirely sure what the best solution would be here, but one easy and temporary fix would be to change the test so that it tests using a method from a different Variant type as a callable, say, Vector2. For example, var vec: Vector2 = Vector2(1.5, 2.5)
print(vec)
var callable: Callable = vec.ceil
print(callable.call()) |
Callable
documentation about methods of native types (reverted) #78274.Makes the following code work:
Note that signals can still only be connected toFixed by #82695.Object
-based callables.