Skip to content

GDScript: Add warning for shadowing global constants#117592

Closed
acs110113 wants to merge 1 commit intogodotengine:masterfrom
acs110113:fix-global-shadowing-warning
Closed

GDScript: Add warning for shadowing global constants#117592
acs110113 wants to merge 1 commit intogodotengine:masterfrom
acs110113:fix-global-shadowing-warning

Conversation

@acs110113
Copy link
Copy Markdown

@acs110113 acs110113 commented Mar 18, 2026

Description

This PR adds a missing warning in GDScript when a local variable or property shadows a global constant (such as PI, OK, or INF).

Previously, shadowing these global constants would happen silently, which could lead to confusing logic errors for users who expect to be using the built-in global values.

Fixes

Changes

  • In gdscript_analyzer.cpp, added a check against GDScriptLanguage::get_singleton()->get_global_map() within the is_shadowing validation logic.
  • Trigger a SHADOWED_VARIABLE warning if a match is found in the global scope.

Validation

Tested with the following script:

var PI = 3.14 # Now triggers a warning
var OK = 0    # Now triggers a warning

@acs110113 acs110113 requested a review from a team as a code owner March 18, 2026 20:00
@dalexeev
Copy link
Copy Markdown
Member

@acs110113
Copy link
Copy Markdown
Author

"Thanks for pointing that out! I'm glad to see this is being addressed in #106984. As this was my first attempt at contributing to Godot, I've learned a lot through the process. I'll close this PR in favor of the existing fix."

@AThousandShips AThousandShips added this to the 4.x milestone Mar 18, 2026
@acs110113 acs110113 closed this Mar 18, 2026
@AThousandShips AThousandShips removed this from the 4.x milestone Mar 18, 2026
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.

3 participants