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

Record coercion can turn an immutable field into a mutable one

Fechada
#9,063 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@cknitt já está trabalhando nisso.

Desde 27/10/2026.

  • #9086 de @cknitt — aberto

Avaliação

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

Direção de pesquisa

Start with Record_coercion.check_record_fields in compiler/ml/record_coercion.ml and read how it checks field names, optionality, runtime names, and field type subtyping. Trace the coercion checks for immutable and mutable fields, then add coverage for the shown ro to rw case and for fields mutable on both sides. Done when the first coercion is rejected and the mutable-to-mutable case requires equal field types.

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

Descrição

What happens

:> between record types accepts a target whose field is mutable when the source's field is not:

type ro = {x: float}
type rw = {mutable x: float}

let toRw = (r: ro) => (r :> rw)

compiles on master (1a49d918e) to

function toRw(r) {
  return r;
}

So a value typed ro, whose x the type system treats as immutable, can be written through the coerced view:

let r: ro = {x: 0.}
let w = (r :> rw)
w.x = 1.   // compiles; r.x is now 1.

Where

Record_coercion.check_record_fields (compiler/ml/record_coercion.ml) compares field names, optionality and runtime names, and passes the field types on for subtyping; it does not compare mutability.

Expected

A coercion should not grant write access the source does not have: a mutable target field requires a mutable source field. Where both are mutable, the field type is read and written, so it has to be equal (invariant) rather than a subtype.

Linguagem predominante
OCaml
Estrelas
7.5k
Forks
483
Merge médio
20h 19min
PRs com merge (30d)
242

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.