Warn if a built-in class property is being used as a reference (it's actually a copy). #7554
OffsetMOSFET
started this conversation in
Editor
Replies: 2 comments 1 reply
-
I think the warning should be triggered by the following construction:
Note that there may be no warning for untyped code. |
Beta Was this translation helpful? Give feedback.
0 replies
-
While documentation is always good, I'd like to question why this inconsistency exists in the first place |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Per the discussion at godotengine/godot#80950, the array and dictionary properties of built-in class objects pass a copy instead of a reference. This behavior is different from a custom class_name, which will pass a reference.
This behavior has personally caused a lot of confusion. It took me a while to realize this was happening because I was used to the class_name behavior and knew these variable types are normally passed by reference. I had first checked the other parts of my code several times before isolating the source to this behavior.
The check I'm think of is: if the rightmost token of a gd_script line is a property of a built-in node of type array or packed*array or dictionary, and if it is not being used for assignment, the parser should warn that a property of a built-in class is pass by copy. This isn't going to catch passing it into a function that will try to modify it, but it's going to help a lot of issues quickly.
Beta Was this translation helpful? Give feedback.
All reactions