GDScript: Use narrowed types from `is` type checks in `if` blocks #123472
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 284 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.338
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #123472"
general
weight: 0.35
Adarsh-Me
When
debug/gdscript/warnings/unsafe_property_accessanddebug/gdscript/warnings/unsafe_method_accessare set to warning or error, accessing a member on a variable that was just checked withisstill reports the warning, even though the check proves the access is safe:Approach
The analyzer now tracks a narrowed type for variables that are tested with
istype tests in the condition of anifstatement (including the operands of anandin that condition):trueblock of that statement is being resolved, occurrences of the checked variable use the tested type instead of its declared type. Since the narrowed type is a hard type, the member access resolves statically and the unsafe access warnings no longer fire.forloop variable with the same name) is not affected.Variantvariables as well, which is the most common case where the unsafe warnings fire onis-checked values.Completions already partially understand
isnarrowing (see #120492), but this PR makes the analyzer itself aware of it, which is what drives the warnings.Tests
modules/gdscript/tests/scripts/analyzer/features/is_type_narrowing.gd: reproduces the issue scenario and checks the code both analyzes and runs correctly.modules/gdscript/tests/scripts/analyzer/warnings/type_narrowing.gd: checks that unsafe access warnings are no longer emitted after anischeck, that they still fire outside the narrowed block, and that an assignment inside the block invalidates the narrowing.All file-based GDScript tests (512) pass, including the binary tokens variant on Linux CI.