Skip to content

GDScript: Improve error message for static/non-static function conflicts#117965

Closed
Lidang-Jiang wants to merge 1 commit intogodotengine:masterfrom
Lidang-Jiang:fix/static-function-error-message
Closed

GDScript: Improve error message for static/non-static function conflicts#117965
Lidang-Jiang wants to merge 1 commit intogodotengine:masterfrom
Lidang-Jiang:fix/static-function-error-message

Conversation

@Lidang-Jiang
Copy link
Copy Markdown

@Lidang-Jiang Lidang-Jiang commented Mar 29, 2026

Fixes #117912.

When a child class defines a function with the same name as a parent's static function (or vice versa), the error messages were not specific enough about the static/non-static mismatch.

Changes:

  1. In check_class_member_name_conflict: When a member name conflicts with a parent class's static function, the error now says The member "X" already exists in parent class Y as a static function. instead of the generic The member "X" already exists in parent class Y.

  2. In resolve_function_signature: Split the validation into two cases:

    • Static mismatch: Shows a specific error like The function "X" is not static, but the parent function of the same name is static.
    • Signature mismatch: Shows the existing signature comparison error (unchanged behavior).
Before
# Case 1: Child non-static overrides parent static
ERROR at line 8: The function signature doesn't match the parent. Parent signature is "my_function() -> void".

# Case 2: Variable overloads parent static function
ERROR at line 8: The member "overload_me" already exists in parent class A.
After
# Case 1: Child non-static overrides parent static
ERROR at line 8: The function "my_function" is not static, but the parent function of the same name is static. A static function cannot be overridden with a non-static function.

# Case 2: Child static overrides parent non-static
ERROR at line 8: The function "my_function" is static, but the parent function of the same name is not static. A non-static function cannot be overridden with a static function.

# Case 3: Variable overloads parent static function
ERROR at line 8: The member "overload_me" already exists in parent class A as a static function.

Tests added:

  • override_static_function_with_non_static.gd/.out
  • override_non_static_function_with_static.gd/.out
  • variable_overloads_superclass_static_function.gd/.out

AI disclosure: AI tooling (Claude Code) was used to assist with writing and reviewing the code. All modifications were reviewed and tested by the author.

Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
@Lidang-Jiang Lidang-Jiang requested review from a team as code owners March 29, 2026 13:09
@Nintorch Nintorch added this to the 4.x milestone Mar 29, 2026
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is overcomplicated. You don't need to add code to check_class_member_name_conflict(), and you don't necessarily need to increase the indentation level in the if (!valid) branch (even though it means the function signature line is being generated in vain). Also, I have a PR #117360 on unifying signature handling, so I could add a more precise error message there.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review! You're right, this is overcomplicated. Since you already have #117360 for unifying signature handling and could add a more precise error message there, I'm happy to close this PR and defer to your approach. Let me know if you'd prefer that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please avoid creating multiple small files to test related features/bugs/warnings. Analyzer and runtime tests support multiple errors. Try to create comprehensive tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, will consolidate into a single comprehensive test file if this PR continues.

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.

GDScript Parsing Error: Missleading error message when overwriting static function

3 participants