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 e1a72ba
Browse filesBrowse the repository at this point in the historyBrowse files
Why:
A public abbreviation could declare a subclass when its arguments were
not all type variables, meant for phantom type hierarchies. The test
was syntactic, so `@instanceOf("Dog") type dog = animal<int>` passed,
and every `animal<int>` was then a dog without a coercion.
A subclass is always a private abbreviation, phantom hierarchies included;
upcasts use `:>`.
Diagnostic added (public subclass of an instantiated class):
Example:
@instanceof("Animal") type animal<'a>
@instanceof("Dog") type dog = animal<int>
Before (diagnostic): none
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.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMkrYaktctdKc4M41WF36t
Signed-off-by: Christoph Knittel <ck@cca.io>
- Require `= private` for every subclass declared with `@instanceOf`, also in phantom type hierarchies, and fold `null` into an untagged variant's object case as it is matched at run time.
Copy file name to clipboardExpand all lines: compiler/ml/UntaggedVariants.md
+7-9Lines changed: 7 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -159,19 +159,18 @@ the annotation of the abbreviated type. The type of a functor parameter, of a
159
159
recursive module being defined, and a locally abstract type `(type a)` are
160
160
abstract only where they are declared: they stand for another type, so they
161
161
cannot be refined. Only a private abbreviation can declare a subclass of the
162
-
class annotated there, or of a `@typeOf("object")` type, or a public one that
163
-
is a strict instance of the superclass type after expansion, as in the
164
-
phantom type hierarchy
165
-
`@instanceOf("Element") type elementLike<'a> = nodeLike<_element<'a>>`. A
166
-
public `type dog = animal` would make every animal a dog without a coercion,
167
-
and so would `type dog = phantom<int>` with `type phantom<'a> = animal`.
162
+
class annotated there, or of a `@typeOf("object")` type, also in a phantom
163
+
type hierarchy (`type dogLike<'a> = private animalLike<_dog<'a>>`). A public
164
+
`type dog = animal` would make every animal a dog without a coercion, and so
165
+
would `type dog = animal<int>` or `type dog = phantom<int>` with
166
+
`type phantom<'a> = animal`.
168
167
169
168
| Declaration | Error | Fixture |
170
169
| --- | --- | --- |
171
170
|`@typeOf("string") type t = option<string>`, `type t<'a> = 'a`, an abbreviation of `unit`, a builtin type, a record or a variant |@typeOf on a type abbreviation must describe an abstract type, ... |`runtime_annotation_on_option.res`, `runtime_annotation_on_type_variable.res`|
172
171
|`@typeOf("number") type t = sym` with `@typeOf("symbol") type sym`| This annotation, @typeOf("number"), contradicts the abbreviated type's annotation, @typeOf("symbol"). |`runtime_annotation_contradicts_manifest.res`|
173
172
|`@instanceOf("Date") type date = X.t` in a functor of `X`, or over `(type a)`|@instanceOf cannot describe the type of a functor parameter, ... |`instance_of_functor_parameter.res`, `type_of_locally_abstract_type.res`|
174
-
|`@instanceOf("Dog") type dog = animal`, or `= phantom<int>` with `type phantom<'a> = animal`| A subclass must be a private abbreviation ... |`instance_of_public_subclass.res`, `instance_of_public_subclass_through_alias.res`|
173
+
|`@instanceOf("Dog") type dog = animal`, `= animal<int>`, or `= phantom<int>` with `type phantom<'a> = animal`| A subclass must be a private abbreviation ... |`instance_of_public_subclass.res`, `instance_of_public_subclass_instance.res`, `instance_of_public_subclass_through_alias.res`|
175
174
|`@instanceOf("Animal") type t = private dog`| Animal appears twice in this chain of abbreviations ... |`instance_of_class_twice_in_chain.res`|
176
175
|`@instanceOf` on a record or variant |@instanceOf can only be used on abstract types and type abbreviations ... |`runtime_annotation_on_record.res`|
177
176
| both annotations | A type can have either @instanceOf or @typeOf, not both. |`runtime_annotation_conflict.res`|
@@ -535,8 +534,7 @@ had to answer, and the answers of rule 5:
535
534
1.**Unchecked claims.** An annotation is trusted, as the type of an external
536
535
is, but checked against the type it abbreviates (rule 5).
537
536
2.**Subclasses.** A class's superclasses are the classes annotated further
538
-
down its chain of private abbreviations, or of strict instances in a
539
-
phantom type hierarchy. A superclass case excludes its subclass cases in
537
+
down its chain of private abbreviations. A superclass case excludes its subclass cases in
540
538
any order, and an upcast value lands in the subclass case (rule 8). The
541
539
relation must be visible where the variant is declared: an interface that
0 commit comments