Semantic Diff

#8914 Warn about untagged payload patterns shadowed by literal cases

7 commits

828bbc414604121156b74143c1b039ccc1b823e2..pr-8914

fdc312f50 · cknitt + Claude · Oct 19, 2026, 13:31 UTC

Warn about untagged payload patterns shadowed by literal cases

A payload pattern whose values are all literal-case values can never match (warning 11/12), and a literal case covers the equal bool payload value in the exhaustiveness check. Fixes #8806.

a9780f6c1 · cknitt + Claude · Oct 20, 2026, 11:53 UTC

Report shadowed payload alternatives when only warning 12 is on

The check for untagged payload patterns shadowed by literal cases ran only when warning 11 was active, so with -w -11+12 or @warning("-11") a dead or-pattern alternative got no warning 12. It now runs when either warning is active; the usefulness analysis is still gated on warning 11.

Example (rescript):

@unboxed type t = | @as("a") A | S(string)@warning("-11")let g = x => switch x { | S("a") => 1 | S("a" | "c") => 2 | S(_) | A => 3 }

Diagnostic (text):

Before: no warningsAfter: Warning 12 on the "a" in S("a" | "c"); the dead S("a") case stayssilent because warning 11 is off.
552b55fe2 · cknitt + Claude · Oct 24, 2026, 11:39 UTC

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.

bbdc52db7 · cknitt + Claude · Oct 25, 2026, 13:58 UTC

Compare bigint patterns and constants by their values

Why

A bigint payload pattern equal to a bigint literal case, such as BI(2n) beside @as(2n) Two, got no warning although it can never match, and a match on a bigint constant was never folded: both treated bigints as never comparable, from before literals were compared by their normalized values.

Bigint pattern constants and bigint constants have their literal, so the shadowed-payload warnings and constant folding compare them as === does: 02n is 2n.

addedDiagnostic shadowed bigint payload

@unboxed type t = | @as(2n) Two | BI(bigint) | S(string)let f = (v: t) =>  switch v {  | BI(02n) => "dead"  | BI(_) => "bigint"  | _ => "other"  }
diagnostic
Before
After
none this match case is unused.2n is the runtime value of constructor Two, so it is always matched as Two, never as BI.
6fd283546 · cknitt + Claude · Oct 25, 2026, 15:03 UTC

Report shadowed polymorphic variant and aliased or-pattern payloads

Why

A polymorphic variant payload equal to a literal case and the alternatives of an or-pattern named with as got no warning, though they can never match.

A polymorphic variant without payload stands for its name, or the number its name spells, as in Lambda.const_polyvar, and an alias is looked through when collecting or-pattern alternatives.

addedDiagnostic a shadowed polymorphic variant payload

@unboxed type t = | @as("Foo") F | P([#Foo | #Bar])let f = x => switch x { | F => 1 | P(#Foo) => 2 | P(_) => 3 }
diagnostic
Before
After
none Warning number 11this match case is unused."Foo" is the runtime value of constructor F, so it is always matched as F, never as P.

addedDiagnostic an aliased or-pattern

@unboxed type t = | @as("a") A | S(string)let f = x => switch x { | S(("a" | "b") as s) => s | S(_) | A => "other" }
diagnostic
Before
After
none Warning number 12this sub-pattern is unused."a" is the runtime value of constructor A, so it is always matched as A, never as S.
7c05b9a79 · cknitt + Claude · Oct 25, 2026, 16:51 UTC

Cover payloads by a bool literal only when they are bools

Why

The exhaustiveness check let a bool literal case cover the equal value of any boolean-kind payload, including a @typeOf("boolean") type that is not bool. The synthesized true pattern did not fit that type, so a match missing the payload was taken as complete.

Only a payload whose type expands to bool gets the synthesized pattern.

addedDiagnostic a @typeOf("boolean") payload

@typeOf("boolean") type jsBool@unboxed type t = | @as(true) Yes | Value(jsBool)let f = (v: t) => switch v { | Yes => 1 }
diagnostic
Before
After
none Warning number 8You forgot to handle a possible case here, for example:| Value(_)
8cb50ef57 · cknitt + Claude · Oct 25, 2026, 16:58 UTC

Keep outer literal cases when looking into nested untagged payloads

Why

Below a second untagged constructor, an or-pattern was checked against the inner variant's literal cases only, although the outer variant's literal cases are tested first on the same value.

The literal cases that take precedence are carried down through untagged payloads, outermost first, each with the payload constructor it shadows.

addedDiagnostic an or-pattern below a nested untagged payload

@unboxed type inner = | @as("x") X | N(int) | S(string)@unboxed type outer = | @as(1) One | W(inner)let f = v => switch v { | One => "one" | W(N(1 | 2)) => "small" | W(_) => "other" }
diagnostic
Before
After
none Warning number 12this sub-pattern is unused.1 is the runtime value of constructor One, so it is always matched as One, never as W.