Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Integer range patterns ending at 2147483647 generate incorrect JavaScript

Aberta
#8,716 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
70/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
javascript, ocaml
Domínio
compilers

Direção de pesquisa

Use the maintenance/12.x compiler with the supplied ReScript switch, first inspecting the generated JavaScript for the integer-range condition. Reproduce the boundary cases and compare the compiler's handling of the exclusive upper bound with the signed 32-bit limit. Done means the generated check accepts 2147483645–2147483647 and rejects 2147483644, including the other listed switch shapes.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

An integer or-pattern ending at 2147483647 (the maximum signed 32-bit integer) compiles to an impossible bound check and rejects values that should match.

Reproduced with the ReScript 12.3.1 compiler on macOS arm64, using the maintenance/12.x code both before and after the change in #8714.

type response = {status: int}

let inRange = (x: response) =>
  switch x {
  | {status: 2147483645 | 2147483646 | 2147483647} => true
  | _ => false
  }

Generated JavaScript, identical before and after #8714:

function inRange(x) {
  let match = x.status;
  if (match >= 2147483645) {
    return match < -2147483648;
  } else {
    return false;
  }
}

Expected and observed results:

Input status Expected Actual
2147483644 false false
2147483645 true false
2147483646 true false
2147483647 true false

The generated condition requires the same integer to be at least 2147483645 and less than -2147483648, so it can never succeed. This appears to be overflow when converting the exclusive upper bound 2147483647 + 1 into a 32-bit integer literal.

The same failure also reproduces with a plain integer switch, nested records, tuples, variant payloads, arrays, and switches on function-call results.

This was found while reviewing #8714 and is a separate, pre-existing bug: the unsigned-range fix in that PR neither introduces nor fixes it.

Linguagem predominante
OCaml
Estrelas
7.5k
Forks
485
Merge médio
1d 34min
PRs com merge (30d)
52

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rescript-lang/rescript

Todas as issues de rescript-lang/rescript

Issues semelhantes

Mais issues de Compilers

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.