-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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: Fix wrong marking of some lines related to Variant as unsafe #69163
Conversation
1318e92
to
e93c490
Compare
Marked if var_e == null: pass # not safe, bad
if var_e != null: pass # not safe, bad
if var_e is Node: pass # not safe, bad |
e93c490
to
9a52902
Compare
Hm... so comparing two Variants is unsafe, have not expected that. Since arrays and now dictionaries are compared by contents, usual comparison may include a conversion and also does not work between two arbitrary types, starting to think that something like |
a0cf3f3
to
4053fb6
Compare
4053fb6
to
12b45d0
Compare
Updated PR to allow inference of hard Variants for variables: var var_i := variant() # error -> safe Removed some inconsistencies between resolving member variables and local ones. Added a test. |
Just went through the PR. Didn't really do a deep dive, but all the code changes make sense to me, as well as the conceptual changes to what is safe and isn't safe :) Just had a question above for something that I noticed afterward was already this way, so I guess no harm in leaving it this way either :) |
12b45d0
to
6ff3362
Compare
Needs rebase! |
045cb74
to
201a6ca
Compare
201a6ca
to
ef81b34
Compare
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.
Looks good to me.
I'm not sure if this is a good idea. Generally one uses type inference expecting to become of that specific type. Since Variant is not really an specific type, it should not be valid for inference, even if the original value is hard typed to be Variant. I fear it's quite easy to do this mistakenly by accident. In this case it would be better to either not use static type at all or explicitly type it as Variant. |
I consider the line itself as type safe. Unsafe lines would be those where
In my view there is a difference between hard variant type and weak variant (untyped) type. With hard variant it should be safe to both read and write variant while with weak one you are told that the value is of some unspecified type, you can expect anything but it does not mean that you can safely set it to anything, so: var a := variant()
a = another_variant() # type safe
var b = variant()
b = another_variant() # type unsafe And it is also strange to punish properly typing things as there is no other way to type "anything" other than with Variant. Also important to highlight that I'm talking about type safety, not simply safety, even type safe code can be wrong and unsafe. This is strictly about types, so maybe |
Updated description to show what is left in this PR. |
Thanks! |
I think most of the things were implemented in other PRs. Here is what remains in this one:
Those will be safe for variant - returning or passing as an argument with explicitly specified Variant type, comparing to null, type checking.