Compiler crash (matching.ml assertion) on dict and optional-field record patterns mixing a value and `?None` on one key
Mantenedores costumam responder em até 1 dia
Um pull request relacionado já foi integrado.
- #8842 de @cknitt — integrado
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- javascript, ocaml
- Domínio
- compilers
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- ReScript
- Estrelas
- 7.5k
- Forks
- 483
- Merge médio
- 1d 4h
- PRs com merge (30d)
- 130
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de rescript-lang/rescript
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 25/100
rescript-lang/rescript#8878 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
rescript-lang/rescript#8806 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
rescript-lang/rescript#8798 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 Meio dia Facilidade para iniciantes 58/100
rescript-lang/rescript#8757 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 40/100
rescript-lang/rescript#8753 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de rescript-lang/rescript
Issues semelhantes
-
`lvm_compact` has no self-hosted twin, and `docs/158` §5 says every language-face component mustAbertabug sev-3 vm
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
Bisect issue233157Abertabisect
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
dtcxzyw/llvm-bisect-service#545 · 1 comentário ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
Mantenedores costumam responder em até 1 dia