Diagnose assignment to indexed property instead of ICE (#7160)#11418
Diagnose assignment to indexed property instead of ICE (#7160)#11418expipiplus1 wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughThis PR replaces an unimplemented assertion when encountering unsupported assignment target forms with a new diagnostic ChangesUnsupported assignment target diagnostics
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR replaces an internal compiler error (ICE) during IR lowering for unsupported assignment targets with a proper diagnostic (E40017), and adds a regression test to ensure the compiler reports the error instead of crashing (notably for assignments like c.b[0] = ... when b is an array-returning property).
Changes:
- Add diagnostic
unsupported-assignment-target(40017) with a guidance message. - Update IR lowering assignment fallback to emit E40017 instead of
SLANG_UNIMPLEMENTED_X("assignment"). - Add a new diagnostics regression test covering indexed assignment into an array-returning property.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
source/slang/slang-lower-to-ir.cpp |
Replaces an ICE in assign() with a user-facing diagnostic for unsupported l-value assignment forms. |
source/slang/slang-diagnostics.lua |
Introduces the new E40017 diagnostic definition and message text. |
tests/diagnostics/indexed-property-assign.slang |
Adds a regression test intended to validate E40017 is emitted for indexed property assignment. |
0050fc3 to
01246a3
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
source/slang/slang-diagnostics.lua (1)
4477-4482:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winPreviously raised concern about workaround validity remains unaddressed.
The diagnostic message suggests "consider assigning to the whole value instead of an individual element," but this workaround may not be valid in all cases where this diagnostic fires. Specifically:
- For properties declared with only
get(noset/ref), whole-value assignment will fail- The test suite does not include a positive test case demonstrating that the suggested workaround actually compiles and runs
Consider either:
- Softening the message to indicate the workaround requires a
setaccessor (e.g., "consider assigning to the whole value instead of an individual element (requires asetaccessor)")- Adding a positive test case to validate the workaround, or
- Removing the workaround suggestion if it's not universally applicable
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 66cec39b-beba-462c-be29-0c229831d5d5
📒 Files selected for processing (3)
source/slang/slang-diagnostics.luasource/slang/slang-lower-to-ir.cpptests/diagnostics/indexed-property-assign.slang
01246a3 to
6694986
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 00144807-7be4-4890-9abf-f3e9638f1966
📒 Files selected for processing (3)
source/slang/slang-diagnostics.luasource/slang/slang-lower-to-ir.cpptests/diagnostics/indexed-property-assign.slang
…7160) Replace the SLANG_UNIMPLEMENTED_X("assignment") internal error with a proper diagnostic (E40017) when attempting to assign to an unsupported l-value form, such as an indexed element of an array-returning property. Closes shader-slang#7160
6694986 to
88019d5
Compare
There was a problem hiding this comment.
Verdict: 🟡 Has issues — 4 gap(s)
Replaces an ICE in assign() with a recoverable diagnostic for the c.b[0] = 1.0 case where b is an array-typed property. The fix direction is right; concerns are around scope of the catch-all default: (it now also swallows Flavor::None / Flavor::Subscript that used to surface as compiler-bug ICEs), source-location recovery brittleness for non-assignExpr callers of assign(), and thin test coverage of the new behavior + missing positive test for the workaround the diagnostic message recommends.
Changes Overview
Diagnostic definition (source/slang/slang-diagnostics.lua)
- Adds
unsupported-assignment-target(E40017) with primary message "assignment target is not supported" and span message suggesting whole-value assignment.
IR lowering recovery (source/slang/slang-lower-to-ir.cpp)
- Replaces
SLANG_UNIMPLEMENTED_X("assignment")in thedefault:branch ofvoid assign(IRGenContext*, LoweredValInfo const&, LoweredValInfo const&)withgetSink()->diagnose(Diagnostics::UnsupportedAssignmentTarget{...}), recovering aSourceLocby walkingirBuilder->getSourceLocInfo()for the first non-zero entry.
Regression test (tests/diagnostics/indexed-property-assign.slang)
- New
DIAGNOSTIC_TEST:SIMPLEexercising assignment toc.b[0]wherebisproperty float b[2]. Asserts E40017 message text via two CHECK lines.
Findings (4 total)
| Severity | Location | Finding |
|---|---|---|
| 🟡 Gap | source/slang/slang-lower-to-ir.cpp:10083 |
default: now catches Flavor::None / Flavor::Subscript (previously ICE'd as compiler bugs); split out Flavor::Simple for the user-facing case and keep SLANG_UNEXPECTED for the rest. |
| 🟡 Gap | source/slang/slang-lower-to-ir.cpp:10086-10095 |
Source-loc chain walk works only because assignExpr pushes an IRBuilderSourceLocRAII; other callers of assign() (applyOutArgumentFixups, addArg, recursive paths, global-var init) don't, so the diagnostic may emit with a stale or empty SourceLoc. |
| 🟡 Gap | tests/diagnostics/indexed-property-assign.slang:30 |
Only c.b[0] = 1.0; is exercised; sibling shapes that hit the same default: (compound assignment, increment, function-return subscript, multi-dim) are not regressed. |
| 🟡 Gap | tests/diagnostics/indexed-property-assign.slang:32 |
The diagnostic recommends "assign to the whole value", but no test asserts that whole-array assignment to an array-typed property setter actually compiles. |
Summary
SLANG_UNIMPLEMENTED_X("assignment")internal error with a proper diagnostic (E40017) when attempting to assign to an unsupported l-value formfoo.b[0] = 1.0wherebis aproperty float b[2])unsupported-assignment-target(40017)Test plan
tests/diagnostics/indexed-property-assign.slangverifies E40017 is emitted instead of crashingCloses #7160