-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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: Assume freed object to be of any Object type #87296
base: master
Are you sure you want to change the base?
Conversation
Makes a lot of sense to me, but we should check other places as well. For example, the following hack is probably no longer needed, at least replacing godot/modules/gdscript/gdscript_lambda_callable.cpp Lines 95 to 101 in 107f296
The old behavior (error when passing It seems that the useful error will not appear with this PR, since it does not appear now if you remove the type hint from the function parameter. Probably a similar check should be done separately, since we check this in many cases: Incomplete list
godot/modules/gdscript/gdscript_vm.cpp Line 825 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 847 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 1362 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 1399 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 2249 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 2560 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 2602 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 2970 in 107f296
godot/modules/gdscript/gdscript_vm.cpp Line 3301 in 107f296
By the way, I noticed an error, godot/modules/gdscript/gdscript_vm.cpp Lines 1721 to 1730 in 107f296
|
What I think is that is if a value is immediately used it should give an error. For instance, passing it to a utility function should raise the error because the user does not have control of its contents, but passing to a user-made function (like in this PR) should not trigger it automatically. Because sometimes the user don't have a lot of control of the source of data. For most cases being freed or I do agree that it should be changed in a few other places to be consistent with this if needed. |
Since we can't check the actual type, we assume the type is correct if the expected type is Object-derived, the same as what happen with null values. Also allow the `is` check to be performed on a freed Object, but in this case it will always return `false`, since the actual type cannot be checked.
69bd9a8
to
cc68731
Compare
Updated this to remove the check in lambda captures, since that is not needed anymore. I also added a change to allow I considered doing the same for casting ( Also added a few test cases to validate the behavior. |
I disagree with
Can you describe which scenarios this helps? Assuming you deliberately have a freed object you cannot store/access/move it safely elsewhere or type-check with the I think that all of the VM breaks should be removed and replaced with gentle linting (that can be toggled off) rather than hard errors that prevent the user from progressing with simpler code. |
Since we can't check the actual type, we assume the type is correct if the expected type is Object-derived, the same as what happen with null values.
Fix #86609
Edit: added an exception for
is
to also allow it on freed objects, but in this case it's alwaysfalse
. Also added a few test cases.