You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fa730fd
Browse filesBrowse the repository at this point in the historyBrowse files
Check runtime annotations against the types they describe
Why:
An annotation on an abbreviation was trusted whatever the abbreviated
type was. `@typeOf("string") type s = option<string>` made `Some(None)`
of `s` the same value as `None`, and two spellings of one type were
recognized differently. Paths such as `Object`, `BigInt` or
`globalThis.Date` were accepted and misrecognized every value or
duplicated another class.
An annotation on an abbreviation must now refine an abstract type that is
not builtin, repeat the abbreviated type's annotation, or declare a subclass
of the class annotated there. A subclass needs a private abbreviation, or a
public one that is a strict instance of the superclass type (a phantom type
hierarchy), and must not repeat a class of its chain. Paths that name no
class to recognize values by are rejected. Payloads of `@unboxed` wrappers of
annotated types are never undefined either, as with `@notUndefined`, and the
function check excludes class cases as the object check does, so the
two-arm form agrees with the `switch` form.
Diagnostic added (annotation on a type that can be undefined):
Example:
@typeof("string") type s = option<string>
After (diagnostic):
@typeof on a type abbreviation must describe an abstract type, or a type with the same annotation. The abbreviated type already has a runtime representation the compiler knows, or can be undefined.
Diagnostic added (subclass on a public abbreviation):
Example:
@instanceof("Animal") type animal
@instanceof("Dog") type dog = animal
After (diagnostic):
A subclass must be a private abbreviation: write `= private ...` so that instances of Animal cannot be used as instances of Dog without a coercion.
Diagnostic added (class path):
Example:
@instanceof("BigInt") type t
After (diagnostic):
Values of type bigint are primitives, not instances of BigInt. Use @typeof("bigint") instead.
JS modified (option of an unboxed wrapper):
Example:
@unboxed type boxedAnimal = BoxedAnimal(animal)
let x: option<boxedAnimal> = Some(BoxedAnimal(a))
Before (js): let x = Primitive_option.some(a);
After (js): let x = a;
JS modified (function case beside a class case):
Example:
@unboxed type handler = Function(int => int) | Callable(callable)
Before (js):
if (typeof handler === "function") {
return "function";
}
After (js):
if (typeof handler === "function" && !(handler instanceof UntaggedCallable)) {
return "function";
}
Review: Why allow public subclasses that are strict instances? `Dom.res`
and WebAPI model class hierarchies with phantom types, such as
`type element<'a> = node<_element<'a>>`, whose subclass types unify with the
superclass type only at the phantom argument. `type dog = animal` is the same
type as `animal` and is rejected.
Review: Why reject `globalThis.C` instead of normalizing it? The compiler
already reads a shadowed class through `globalThis`, so the prefix adds
nothing, and one spelling per class keeps the duplicate and subclass checks,
which compare paths, exact.
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>
0 commit comments