Skip to content
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 subscript resolution on constant non-metatype GDScript base #92544

Merged

Conversation

dalexeev
Copy link
Member

@dalexeev dalexeev commented May 30, 2024

#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 use Variant::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 the is_meta_type flag sometimes leads to strange bugs.

Some users add unnecessary type hints to const-preload, which removes metatypes.

const MyClass: GDScript = preload("./my_class.gd")
var test := MyClass.InnerClass.new()
#                   ^^^^^^^^^^
# The specified type `GDScript` has no member `InnerClass`,
# but the value has and this is known in advance.

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 the is_meta_type flag, the static members of the class are checked first, and then the non-static members of the GDScript class. For GDScript with the is_meta_type flag, only static class members are still checked.

@dalexeev dalexeev added this to the 4.3 milestone May 30, 2024
@dalexeev dalexeev requested a review from a team as a code owner May 30, 2024 12:54
@dalexeev dalexeev force-pushed the gds-fix-const-non-metatype-subscript branch from 1fd0bc5 to 9c5f9a5 Compare May 30, 2024 12:57
@dalexeev dalexeev changed the title GDScript: Fix subscript resolution on constant non-metatype base GDScript: Fix subscript resolution on constant non-metatype GDScript base May 30, 2024
@dalexeev dalexeev force-pushed the gds-fix-const-non-metatype-subscript branch from 9c5f9a5 to 269f076 Compare May 30, 2024 14:03
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. Thanks for the quick fix, and the detailed explanations!

@akien-mga akien-mga merged commit ce82984 into godotengine:master May 30, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in "GDScript: fix segfault on invalid script" with const foo : GDScript= preload(...)
3 participants