GDScript: Fix subscript resolution on constant non-metatype GDScript base #92544
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
const foo : GDScript= preload(...)
#92534.#92035 exposed a bug with the static analyzer tries to get
GDScript
properties when they might be invalid (now there is a guard against it). This is due to the fact that when reducing subscript on a constant base, we useVariant::get_named()
, while we should use the analyzer. In #79510, I fixed a related bug, but I didn't take into account that a constant value could have a broader type due to type hints and casting.We also have a quirk that GDScript classes are both types and values. What causes collisions (#75392, #76414) is whether you mean a static class member or a non-static member of the
GDScript
resource (for instance,resource_path
). Also, we don't have first class types and theis_meta_type
flag sometimes leads to strange bugs.Some users add unnecessary type hints to
const
-preload
, which removes metatypes.It might make sense to distinguish between a GDScript class as a type and as a value, but we proceed from the current state of affairs and strive to maintain backward compatibility. Now, for a constant
GDScript
base without theis_meta_type
flag, the static members of the class are checked first, and then the non-static members of theGDScript
class. ForGDScript
with theis_meta_type
flag, only static class members are still checked.