Untagged variant switch with a default arm matches instances and literals in the wrong case
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, ocaml
- Área
- compilers
Línea de trabajo
Start with compiler/ml/lam_compile.ml, especially compile_untagged_cases and compile_general_cases, then compare the behavior with rules 7 and 8 in compiler/ml/UntaggedVariants.md. Run or add compiler cases for the instance and literal examples in the issue; done means both produce other for the shown inputs while preserving the documented matching rules.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
A switch on an untagged variant with a _ arm can match a value in the wrong case. This happens when the default survives into the untagged dispatch, which takes a variant with several cases; with fewer cases the match compiler expands _ into the remaining cases and the result is correct.
An instance lands in the object case.
@unboxed type t = D(Date.t) | R(RegExp.t) | O({x: int}) | S(string) | I(int) | F(int => int)
@inline(never) let id = (x: t) => x
let f = v => switch v { | O(_) => "O" | S(_) => "S" | _ => "other" }
Console.log(f(id(D(Date.make()))))
function f(v) {
switch (typeof v) {
case "object" :
return "O";
case "string" :
return "S";
default:
return "other";
}
}
Output: O; expected other. The case "object" lacks the !(v instanceof Date) && !(v instanceof RegExp) exclusion that the object check gets elsewhere.
A literal lands in the string case.
@unboxed type t = | @as("lit") Lit | S(string) | I(int) | B(bool) | O({x: int}) | F(int => int)
@inline(never) let id = (x: t) => x
let f = v => switch v { | S(_) => "S" | O(_) => "O" | _ => "other" }
Console.log(f(id(Lit)))
function f(v) {
switch (typeof v) {
case "string" :
return "S";
case "object" :
return "O";
default:
return "other";
}
}
Output: S; expected other. No test for the literal "lit" is emitted before the typeof switch.
Both contradict compiler/ml/UntaggedVariants.md: rule 7 ("A value equal to a literal therefore belongs to the literal's case") and rule 8 ("In both forms a value of an instance case never lands in the object case"). The cause is presumably in lam_compile.ml:compile_untagged_cases / compile_general_cases when the switch keeps a Default and the instance and literal cases it would need to exclude have no arm of their own (not yet confirmed).
- Lenguaje dominante
- OCaml
- Estrellas
- 7.5k
- Forks
- 483
- Merge medio
- 21 h 8 min
- PR fusionados (30 d)
- 183
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
- Tiene una 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
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
rescript-lang/rescript#8996 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 70/100
rescript-lang/rescript#8997 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
rescript-lang/rescript#8994 ·
Los mantenedores suelen responder en 1 día
-
Issues from differential semantic drift analysis (a7721303 to b123b7c3)Posiblemente ocupada @cknitt la tomó hoy. Abierto
rescript-lang/rescript#8980 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Doc-comment attributes: editor analysis accepts `@ocaml.doc`/`@ns.doc`, genType and the printer do notPosiblemente ocupada @cknitt la tomó hoy. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
rescript-lang/rescript#8978 ·
Los mantenedores suelen responder en 1 día
Todos los issues de rescript-lang/rescript
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 1 día
-
bug P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
duplicate
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
numba/numba#10939 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Quantinuum/tket#2255 ·
Los mantenedores suelen responder en 1 día
-
REPL and --show-tokens abort with "Token conversion not implemented yet" on .xor., byte and in outAbiertobug low priority tokenizer
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día