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

Integer range patterns on record fields match values below the range

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

Mantenedores costumam responder em até 1 dia

Um pull request relacionado já foi integrado.

  • #8714 de @mvaled — integrado

Avaliação

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

Direção de pesquisa

Start in Js_exp_make.is_out and compare its fallback handling with commit 6d78c5832781165685b45bb2092d8edf170b75ae, where to_uint32 was removed. Reproduce the record-field range example and inspect the generated JavaScript. Done means values below 502 no longer match the 502–504 range while the valid range still does.

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

Descrição

Reported in the forum: https://forum.rescript-lang.org/t/potential-bug-in-code-generation-of-subpattern-of-integers-httperror-status-502-503-504-rescript-12-and-13/7598

Matching a contiguous range of integers on a value that is not a plain variable (e.g. a record field) generates a signed comparison, so every value below the range also matches.

type response = {status: int}
let isRetriable = error =>
  switch error {
  | {status: 502 | 503 | 504} => true
  | _ => false
  }

ReScript 12 and 13 (alpha) generate:

function isRetriable(error) {
  return (error.status - 502 | 0) <= 2;
}

which returns true for 404, 500, 501, etc. ReScript 10 and 11 generated (error.status - 502 >>> 0) <= 2, which is correct.

A bare switch x { | 502 | 503 | 504 => ... } is not affected; it compiles to !(x > 504 || x < 502).

The unsigned conversion in the fallback case of Js_exp_make.is_out was lost in https://github.com/rescript-lang/rescript/commit/6d78c5832781165685b45bb2092d8edf170b75ae when to_uint32 was removed.

Linguagem predominante
OCaml
Estrelas
7.5k
Forks
484
Merge médio
20h 27min
PRs com merge (30d)
120

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.