Untagged variants: no warning for patterns shadowed by a literal case, and a spurious non-exhaustive warning for bool payloads
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- ocaml
- Área
- compilers
Línea de trabajo
Start by reading parmatch.ml, which the issue identifies as the site of the exhaustiveness check, and find the adjacent unused-case check for the warning proposal. Review the related issues #8631, #8632, and #8777 for runtime value comparisons and overlap cases. Done means dead untagged payload patterns are warned about and the bool example is exhaustive without an unreachable failure.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
An untagged variant may have a literal case whose runtime value a payload case can also hold (#8632, #8777):
@unboxed type t = | @as("a") A | S(string)
Matching tests declared literals first, so the pattern S("a") can never match. The value "a" always goes to A, or to a wildcard if there is no A arm. The type checker treats S("a") and A as different, which causes two problems.
1. No warning for patterns that can never match
Checked on master. None of these produce a warning, and each S(...) arm marked dead is dead in the generated JS:
let f1 = x => switch x { | A => 1 | S("a") => 2 | S(_) => 3 } // S("a") dead
let f2 = x => switch x { | S("a") => 2 | A => 1 | S(_) => 3 } // dead even as first arm
let f3 = x => switch x { | S("a") => 2 | _ => 3 } // compiles to `return 3`
let f4 = x => switch x { | S("a" | "b") => 2 | _ => 3 } // the "a" alternative is dead
The same applies when:
- the literal comes from the constructor name (
Primary | Color(string):Color("Primary")is dead); - an int literal overlaps a float payload (
@as(1) One | F(float):F(1.0)is dead); - a nested untagged constant has the same value (
@as("x") X | W(inner)whereinnerhas@as("x") P:W(P)is dead).
In a refutable binding such as let l = (S("a") as v) => v, the pattern never matches at all, so every call with S("a") throws Match_failure.
Proposal: warn on a constructor pattern S(p) of an untagged variant when every value p can match is the runtime value of a literal case in the same variant. Use warning 11 (unused case) for a whole arm and warning 12 (redundant sub-pattern) for or-pattern alternatives. Suggested message: "this pattern can never match: "a" is the value of constructor A".
Notes:
- The check is local to each pattern and doesn't depend on arm order, so it can run beside
check_unusedwithout touching the exhaustiveness algorithm. - Values must be compared the way they are at runtime, as in #8631:
1and1.0are equal, bigint spellings differ (1_0n=10n), ints use their 32-bit value, and a constructor without@asis represented by its own name. - Guards (
S(s) if s == "a") are out of scope.
2. Spurious non-exhaustive warning for bool payloads
With #8777 a bool payload can partly overlap a literal:
@unboxed type b = | @as(true) Yes | Ans(bool)
let g = x => switch x { | Yes => 1 | Ans(false) => 2 }
This match covers every value, yet the compiler reports warning 8 with the counterexample Ans(true) and emits an unreachable Match_failure throw. The only way to silence it is to add the dead arm Ans(true) => ..., which point 1 would then flag. The two parts therefore need to land together, or the bool case ends up with no warning-free way to write the match.
Proposal: during the exhaustiveness check only, treat a literal-case pattern as also covering the payload values equal to it, e.g. check Yes as Yes | Ans(true). This is harder than point 1 because it changes parmatch.ml. For string and number payloads it rarely matters, since their domain is infinite, but for bool it does.
Related: #8632, #8777, #8631, rescript-lang/rescript-lang.org#1337
- Lenguaje dominante
- OCaml
- Estrellas
- 7.5k
- Forks
- 484
- Merge medio
- 18 h 19 min
- PR fusionados (30 d)
- 116
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rescript-lang/rescript
-
Build-test fixtures that no longer test what they claimPosiblemente ocupada @cknitt la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
rescript-lang/rescript#8827 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
rescript-lang/rescript#8833 · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
rewatch watch on Linux stops watching a source folder when an overlapping recursive source folder is removed from rescript.jsonPosiblemente ocupada @cknitt la tomó hoy. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 35/100
rescript-lang/rescript#8825 ·
Los mantenedores suelen responder en 1 día
-
Formatter drops comments in dict patterns, variant spread patterns and dict literal spreadsPosiblemente ocupada @cknitt la tomó hoy. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
rescript-lang/rescript#8820 ·
Los mantenedores suelen responder en 1 día
-
JSX preserve mode spreads an `@unboxed` props record (`{..."x"}` instead of `"x"`)Posiblemente ocupada @cknitt la tomó hoy. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 25/100
rescript-lang/rescript#8813 ·
Los mantenedores suelen responder en 1 día
Todos los issues de rescript-lang/rescript
Issues similares
-
bug format I/O medium priority rt_lib
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Invalid model / false unsat: to_fp of real * 2^int with a symbolic rounding mode treats RTN as RTZAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
KhronosGroup/SPIRV-LLVM-Translator#4082 ·
Los mantenedores suelen responder en 2 días
-
bug diagnostics
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
vx-lang/Vx#1718 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
bradcypert/plum#227 ·
Los mantenedores suelen responder en 1 día