Skip to content

Commit da12cf0

Browse files
cknittclaude
andcommitted
Describe the shadowed payload warnings in the spec
Rule 7 says which payload patterns a literal case shadows, which warnings report them, and how a literal case counts in the exhaustiveness check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent c8ed365 commit da12cf0

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

‎compiler/ml/UntaggedVariants.md‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,22 @@ otherwise it reaches the default through the payload dispatch, which then
330330
checks its last arm. A `null` literal that only the object check would
331331
accept adds `x !== null` to that check instead (rule 9).
332332

333-
- Implementation: `lam_compile.ml:compile_switch`.
333+
A payload pattern whose every value is a literal case's can therefore never
334+
match, and is reported: warning 11 for an arm, such as `S("a")` beside
335+
`@as("a") A`, and warning 12 for an alternative of an or-pattern, both with
336+
"\"a\" is the runtime value of constructor A, so it is always matched as A,
337+
never as S". Values are compared as `===` compares them (rule 6). For the
338+
exhaustiveness check a literal case covers the payload values equal to it, so
339+
`Yes | Ans(false)` is a complete match of `@as(true) Yes | Ans(bool)`.
340+
341+
- Implementation: `lam_compile.ml:compile_switch`;
342+
`parmatch.ml` (shadowed payload patterns, exhaustiveness).
334343
- Tests: `spec_test` rule 7; `tests/tests/src/untagged_variants_heuristic.res`
335-
(literals that skip the `switch`).
336-
- Shaped by #6125, #7128, #7135.
344+
(literals that skip the `switch`); `unboxed_variant_fold_test.res`
345+
(`answerName2`); fixtures `warning_11_untagged_literal_shadows_payload.res`,
346+
`warning_11_untagged_literal_shadows_payload_kinds.res`,
347+
`warning_12_untagged_literal_shadows_or_pattern.res`.
348+
- Shaped by #6125, #7128, #7135, #8806.
337349

338350
### 8. Payload cases
339351

0 commit comments

Comments
 (0)