Repository navigation
Commit 4e57a5a
A union of null and several types can be tested for truth (#540)
`if (x)` with `x: boolean | string | null` failed to compile ("can't
instantiate function. '___cast' not all generic types can be
identified"), and so did `if (enabled && handle)` for a boolean and a
`Handle | null`, whose `&&` makes such a union. The generated union cast
answered `return t` for the null member, which strict null mode refuses
to cast to boolean. Cast to boolean, a null or undefined member is now
false, as castFromAny already does for an `any`.
A null `Handle` carries the class's tag in that union, and the class
member's `instanceof` test read its vtable through the null pointer; for a
truth test of a union with one class, the class member is now just tested
for null.
Reported in docs/bugs/native-ts-graphics-findings.md (issue 6).
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 5391b05 commit 4e57a5a
3 files changed
Lines changed: 92 additions & 1 deletion
File tree
- tslang
- lib/TypeScript
- test/tester
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2272 | 2272 | | |
2273 | 2273 | | |
2274 | 2274 | | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
| 2280 | + | |
| 2281 | + | |
2275 | 2282 | | |
2276 | 2283 | | |
2277 | 2284 | | |
| |||
2281 | 2288 | | |
2282 | 2289 | | |
2283 | 2290 | | |
2284 | | - | |
| 2291 | + | |
| 2292 | + | |
| 2293 | + | |
| 2294 | + | |
| 2295 | + | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
| 2299 | + | |
| 2300 | + | |
| 2301 | + | |
| 2302 | + | |
| 2303 | + | |
2285 | 2304 | | |
2286 | 2305 | | |
2287 | 2306 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| 410 | + | |
410 | 411 | | |
411 | 412 | | |
412 | 413 | | |
| |||
931 | 932 | | |
932 | 933 | | |
933 | 934 | | |
| 935 | + | |
934 | 936 | | |
935 | 937 | | |
936 | 938 | | |
| |||
2044 | 2046 | | |
2045 | 2047 | | |
2046 | 2048 | | |
| 2049 | + | |
2047 | 2050 | | |
2048 | 2051 | | |
2049 | 2052 | | |
| |||
| 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 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
0 commit comments