Repository navigation
Commit 9c4de0a
Show existential types as $a and name their constructor (#9080)
* Show existential types as $a and name their constructor
Why:
An existential type of a GADT constructor is an abstract type named
`$Any_'a` internally, and that name was printed as is in errors and
hover. It is now printed `$a`, as in OCaml 5, and the escape error
says which constructor binds it instead of calling it a type
constructor.
Diagnostic modified (existential escape):
Example:
type rec any = Any('a): any
let get = (Any(x)) => x
Before (diagnostic):
This has type: $Any_'a
But it's expected to have type: 'a
The type constructor $Any_'a would escape its scope
After (diagnostic):
This has type: $a
But it's expected to have type: 'a
$a is an existential type bound by the constructor Any.
It is only known in the scope of the pattern that matches Any.
Review: Why decode the name instead of recording the constructor?
The name already holds both parts, so printing needs no table that
would have to be reset between compilations in one process.
Fixes: #9068
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Give distinct existential types distinct names
Codex review on #9080: printing `$C_'a` as `$a` made existentials of
different constructors that bind the same variable print alike, so a
mismatch between them read `$a` vs `$a`. Existentials are now named `$a`
before the compiler makes the name unique, as OCaml 5 does, so the second
one is `$a1`; the constructor binding each name is recorded for the escape
explanation instead of being decoded from the name.
Diagnostic modified (existentials of two constructors):
Example:
type rec any = First('a): any | Second('a): any
let same = (First(x), Second(y)) => x == y
Before (diagnostic):
This has type: $a
But it's being compared to something of type: $a
After (diagnostic):
This has type: $a1
But it's being compared to something of type: $a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
* Key existential constructors by identifier
Codex review on #9080: the constructor of each existential was recorded by
its name, but the counter that makes names unique is reset for each
binding, so a nested module's `$a` could overwrite the constructor of an
outer `$a`. It is recorded by the identifier's stamp now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gLMawVgtmiKy3TMBc3
Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo
Signed-off-by: Christoph Knittel <ck@cca.io>
---------
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 9ceeb96 commit 9c4de0a
12 files changed
Lines changed: 111 additions & 6 deletions
File tree
- changes
- compiler/ml
- tests
- analysis_tests/tests/src
- expected
- 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 | |
|---|---|---|---|
| |||
933 | 933 | | |
934 | 934 | | |
935 | 935 | | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
936 | 946 | | |
937 | 947 | | |
938 | 948 | | |
939 | 949 | | |
940 | 950 | | |
941 | 951 | | |
942 | 952 | | |
| 953 | + | |
| 954 | + | |
943 | 955 | | |
944 | 956 | | |
945 | | - | |
| 957 | + | |
946 | 958 | | |
947 | 959 | | |
948 | | - | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
949 | 965 | | |
950 | 966 | | |
951 | 967 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1300 | 1300 | | |
1301 | 1301 | | |
1302 | 1302 | | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
1303 | 1320 | | |
1304 | 1321 | | |
1305 | 1322 | | |
1306 | 1323 | | |
1307 | 1324 | | |
1308 | | - | |
1309 | | - | |
| 1325 | + | |
1310 | 1326 | | |
1311 | | - | |
1312 | | - | |
| 1327 | + | |
1313 | 1328 | | |
1314 | 1329 | | |
1315 | 1330 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments