rescript-lang / rescript-lang/rescript

Record spread from smaller to bigger record type set doesn't work

Open
#6,505 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

I observed some weird behavior while working on my app, so I tried to reduce the problem to a minimal example.

type a = {
  title: string,
  ingredients: array<string>,
}

type b = {
  ...a,
  parsedIngredients: array<string>,
}

// This works
let a: a = {
  title: "Pizza",
  ingredients: ["1 EL Oil", "1 EL flour"],
}

// EXPECTED: This should compile
let b: b = {
  // ERROR: This has type `a`, but it's expected to have type `b`
  ...a,
  parsedIngredients: ["Oil", "Flour"],
}

I don't know if I misunderstood the record type spread feature, but IMO from an intuition perspective I'd expect value b to initialize just fine, since we are essentially spreading in all the values that a has, plus the parsedIngredients value that's required from b.

Does this work as expected?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the minimal record-spread example in the issue first; no source file, test, or compiler entry point is named. Trace the record-spread type-checking behavior and add a regression test showing whether a smaller record can initialize the larger type, then confirm the expected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.