Commit 3caf478
Fix numeric literal type checking against union types
The bug occurred when checking numeric literals (e.g., 2) against
union types containing exact numeric values (e.g., (U 1 2)).
Root cause:
- Value types like (-val 2) were not being interned, so each call
to (-val 2) created a new instance
- When unions were created from type annotations like (U 1 2), they
stored specific Value instances in their element hash
- During subtype checking, a freshly created (-val 2) would not
match the Value instance stored in the union's hash, causing
the subtype check to fail
- This made (f 2) fail type checking when f : (U 1 2) -> ...
Solution:
1. Added value-intern-table to intern all Value type instances
2. Modified Value's custom constructor to use intern-single-ref!
3. Now (-val 2) always returns the same instance, making hash
lookups in subtype checking work correctly
Behavior:
- Without expected type: literals get general types (e.g., -PosByte)
- With expected type: literals get the expected type after successful
subtype checking
This fixes the asymmetry where (f 1) worked but (f 2) failed.
Originally reported by Matthias Felleisen.1 parent 5c1da6d commit 3caf478
2 files changed
Lines changed: 42 additions & 1 deletion
File tree
- typed-racket-lib/typed-racket/rep
- typed-racket-test/succeed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
939 | 939 | | |
940 | 940 | | |
941 | 941 | | |
942 | | - | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
943 | 947 | | |
944 | 948 | | |
945 | 949 | | |
| |||
| 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 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments