Skip to content

Commit 3720f2c

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 9d20180 commit 3720f2c

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
@@ -339,10 +339,22 @@ otherwise it reaches the default through the payload dispatch, which then
339339
checks its last arm. A `null` literal that only the object check would
340340
accept adds `x !== null` to that check instead (rule 9).
341341

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

347359
### 8. Payload cases
348360

0 commit comments

Comments
 (0)