Repository navigation
Commit dbe05fb
Declare the runtime class or typeof of abstract types
Why:
Untagged variants recognize payloads of abstract types only from a
hard-coded list of stdlib type names, which knows no subclasses and is
closed to bindings such as WebAPI's (#7147).
`@instanceOf("Class")` and `@typeOf("…")` on an abstract type or a type
abbreviation state how its values are recognized at run time. The
classifier reads them along the type's expansion chain: the outermost one
decides, and the classes annotated further down a chain of private
abbreviations are its superclasses. A class check excludes the subclasses
that are cases too. Both imply that a value is never undefined. The name
list stays as fallback for types without annotations. Editor completion
offers both, and `@notUndefined`, which was listed with the file-level
`@@` decorators, now completes after a single `@`.
Representation added (untagged variant payload):
Example:
@instanceof("Animal") type animal
@instanceof("Dog") type dog = private animal
@typeof("symbol") type sym
@unboxed
type t = Animal(animal) | Dog(dog) | Sym(sym)
After (representation):
Animal(a) ↦ a, recognized by a instanceof Animal && !(a instanceof Dog)
Dog(d) ↦ d, recognized by d instanceof Dog
Sym(s) ↦ s, recognized by typeof s === "symbol"
Diagnostic added (invalid annotation):
Example:
@typeof("undefined") type t
After (diagnostic):
@typeof expects one of "string", "number", "bigint", "boolean", "symbol", "function" or "object", not "undefined".
Review: Why `@instanceOf`/`@typeOf` rather than one `@runtime(...)`
attribute? They read like the JavaScript checks they produce, take a single
string like `@as` and `@tag`, and sit next to the existing `@notUndefined`.
Review: Why also on public abbreviations? The typed array types are public
aliases of `TypedArray.t<'a>` that users pass to `TypedArray` functions, so
they can only be told apart by the name as written, as the name list does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fc7LEuyEfynjaKCVEBPmTF
Signed-off-by: Christoph Knittel <ck@cca.io>1 parent c59f1fc commit dbe05fb
34 files changed
Lines changed: 841 additions & 148 deletions
File tree
- analysis/src
- changes
- compiler
- core
- ext
- ml
- tests
- analysis_tests/tests/src
- expected
- build_tests/super_errors
- expected
- fixtures
- ounit_tests
- tests/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
301 | 341 | | |
302 | 342 | | |
303 | 343 | | |
| |||
331 | 371 | | |
332 | 372 | | |
333 | 373 | | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | 374 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1385 | 1385 | | |
1386 | 1386 | | |
1387 | 1387 | | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
1388 | 1398 | | |
1389 | 1399 | | |
1390 | 1400 | | |
1391 | 1401 | | |
1392 | 1402 | | |
| 1403 | + | |
1393 | 1404 | | |
1394 | 1405 | | |
1395 | | - | |
| 1406 | + | |
1396 | 1407 | | |
1397 | 1408 | | |
1398 | 1409 | | |
| |||
1417 | 1428 | | |
1418 | 1429 | | |
1419 | 1430 | | |
1420 | | - | |
1421 | | - | |
| 1431 | + | |
1422 | 1432 | | |
1423 | 1433 | | |
1424 | 1434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
885 | 885 | | |
886 | 886 | | |
887 | 887 | | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
888 | 893 | | |
889 | 894 | | |
890 | 895 | | |
891 | 896 | | |
892 | 897 | | |
893 | 898 | | |
894 | | - | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
895 | 902 | | |
896 | 903 | | |
897 | 904 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
0 commit comments