Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one key

Cerrado
#8,810 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Ya se ha fusionado un pull request relacionado.

  • #8842 de @cknitt — fusionado

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
javascript, ocaml
Área
compilers

Línea de trabajo

Start with compiler/ml/matching.ml at get_args_constr around line 1236, then read compiler/ml/dict_pattern.ml around lines 73–102 to understand how dict keys become optional record labels. Reproduce the crash with the supplied dict and optional record pattern examples, and inspect the existing compiler tests for matching. Done means both examples compile without an assertion failure; pull request #8842 is already open.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Found by adversarial experiments on semantic analysts.

What is broken

This match makes bsc crash:

let f = (d: dict<int>) =>
  switch d {
  | dict{"x": 1} => 0
  | dict{"y": 2} => 0
  | dict{"x": ?None} => 1
  | _ => 2
  }
$ bsc -nopervasives C1.res
Fatal error: exception File "compiler/ml/matching.ml", line 1236, characters 9-15: Assertion failed

Expected: it compiles. The compiler at ece8b148 produces:

function f(d) {
  if (d.x !== 1 && d.y !== 2) {
    if (d.x !== undefined) { return 2; } else { return 1; }
  } else { return 0; }
}

The assertion is in get_args_constr: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/matching.ml#L1233-L1236

The same crash happens with a record type that has optional fields, both at master and at ece8b148:

type r = {x?: int, y?: int}
let f = (d: r) =>
  switch d {
  | {x: 1} => 0
  | {y: 2} => 0
  | {x: ?None} => 1   // `?Some(3)` crashes too
  | _ => 2
  }

Any two of the three cases compile. The crash needs a value pattern and an optional pattern (?None or ?Some(_)) on the same key, with a case on another key between them.

Introduced

The record crash is older. Dict patterns reach it since #8751 (e6c46f23b), which lowers every key of a match to one optional record label: https://github.com/rescript-lang/rescript/blob/8d51b9ce7/compiler/ml/dict_pattern.ml#L73-L102

Impact

The compiler crashes, with no source location, on an ordinary dict pattern match that compiled before #8751.

Lenguaje dominante
ReScript
Estrellas
7.5k
Forks
483
Merge medio
1 d 1 h
PR fusionados (30 d)
120

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rescript-lang/rescript

Todos los issues de rescript-lang/rescript

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.