Repository navigation
Commit bcf81d1
Treat an empty record literal with mutable fields as expansive (#9152)
Why:
The value restriction looks for mutable fields among a record
literal's entries, but `{}` of an all-optional record has none, so
it was always non-expansive and its type variables were generalized
even when a field is mutable (#9150). It now looks up the record's
declaration and requires every field to be immutable.
Diagnostic added (empty record literal with a mutable field):
Example:
type cell<'a> = {tag?: int, mutable value?: 'a}
let cell: cell<_> = {}
cell.value = Some(1)
let s: option<string> = cell.value
Before (diagnostic): none; `s` holds the number 1 at run time
After (diagnostic):
This has type: option<int>
But it's expected to have type: option<string>
The incompatible parts:
int vs string
Review: Does `{}` of an immutable record still generalize? Yes; the
super_errors fixture uses one such value at both option<int> and
option<string> before reaching the error.
Claude-Session: https://claude.ai/code/session_01Kbf3gKyiYMf54wPRxFdUWe
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 940b761 commit bcf81d1
4 files changed
Lines changed: 35 additions & 1 deletion
File tree
- changes
- compiler/ml
- tests/build_tests/super_errors
- expected
- fixtures
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2095 | 2095 | | |
2096 | 2096 | | |
2097 | 2097 | | |
2098 | | - | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
2099 | 2106 | | |
2100 | 2107 | | |
2101 | 2108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments