Skip to content

Commit 9d1eebb

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 be73b0a commit 9d1eebb

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

288-
- Implementation: `lam_compile.ml:compile_switch`.
288+
A payload pattern whose every value is a literal case's can therefore never
289+
match, and is reported: warning 11 for an arm, such as `S("a")` beside
290+
`@as("a") A`, and warning 12 for an alternative of an or-pattern, both with
291+
"\"a\" is the runtime value of constructor A, so it is always matched as A,
292+
never as S". Values are compared as `===` compares them (rule 6). For the
293+
exhaustiveness check a literal case covers the payload values equal to it, so
294+
`Yes | Ans(false)` is a complete match of `@as(true) Yes | Ans(bool)`.
295+
296+
- Implementation: `lam_compile.ml:compile_switch`;
297+
`parmatch.ml` (shadowed payload patterns, exhaustiveness).
289298
- Tests: `spec_test` rule 7; `tests/tests/src/untagged_variants_heuristic.res`
290-
(literals that skip the `switch`).
291-
- Shaped by #6125, #7128, #7135.
299+
(literals that skip the `switch`); `unboxed_variant_fold_test.res`
300+
(`answerName2`); fixtures `warning_11_untagged_literal_shadows_payload.res`,
301+
`warning_11_untagged_literal_shadows_payload_kinds.res`,
302+
`warning_12_untagged_literal_shadows_or_pattern.res`.
303+
- Shaped by #6125, #7128, #7135, #8806.
292304

293305
### 8. Payload cases
294306

0 commit comments

Comments
 (0)