rescript-lang / rescript-lang/rescript
Record spread from smaller to bigger record type set doesn't work
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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