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 667b281
Browse filesBrowse the repository at this point in the historyBrowse files
Close the gaps the re-review of runtime annotations found
Why:
An annotation could refine a functor parameter's or a locally abstract
type, which stands for any type: `@instanceOf("Date") type d = X.t` in a
functor applied to `option<int>` made `Some(None)` collapse to `None`. An
abbreviation through an alias passed as a phantom subclass, an interface
hiding a payload's class was rejected although master accepts it, and two
`@instanceOf` attributes were reported as a conflict between the two
kinds.
Annotations on the type of a functor parameter, of a recursive module being
defined, or on a locally abstract type are rejected. The phantom-hierarchy
exception reads the abbreviation's arguments after expansion. A class can
be declared over a `@typeOf("object")` type. An interface case with an
unknown payload agrees with any payload of the implementation, since it is
the only payload case and is never checked.
Diagnostic added (a type that stands for another one):
Example:
module Make = (X: {type t}) => {
@instanceof("Date") type date = X.t
}
After (diagnostic):
@instanceof cannot describe the type of a functor parameter, of a recursive module being defined, or a locally abstract type: such a type stands for another one, whose values can be anything.
Diagnostic added (public subclass through an alias):
Example:
@instanceof("Animal") type animal
type phantom<'a> = animal
@instanceof("Dog") type dog = phantom<int>
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 removed (an interface hiding a payload's class):
Example:
// A.resi
type t
@unboxed type v = | @as("n") N | P(t)
// A.res
type t = Date.t
@unboxed type v = | @as("n") N | P(t)
Before (diagnostic):
The internal representations for case P are not equal
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>
Copy file name to clipboardExpand all lines: analysis/src/completion_decorators.ml
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -303,7 +303,7 @@ You will need this decorator whenever you want to use a JSX component in ReScrip
303
303
[
304
304
{|The `@instanceOf` decorator states that the values of an abstract type are instances of a global JavaScript class. Such a type can be the payload of an untagged variant case, which is then recognized with `instanceof`, andis never `undefined`, like with `@notUndefined`.
305
305
306
-
A private abbreviation of another annotated type declares a subclass, so that the subclass case is checked first.
306
+
A private abbreviation of another annotated type declares a subclass. A caseofthe superclass then excludes the instances of a subclass that is a case too, whatever the order of the cases.
Copy file name to clipboardExpand all lines: compiler/ml/UntaggedVariants.md
+16-7Lines changed: 16 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -144,20 +144,27 @@ superclass.
144
144
145
145
An annotation on an abbreviation must agree with the abbreviated type. It can
146
146
refine an abstract type that is not builtin and has no annotation, or repeat
147
-
the annotation of the abbreviated type. Only a private abbreviation can
148
-
declare a subclass of the class annotated there, or a public one that is a
149
-
strict instance of the superclass type, as in the phantom type hierarchy
147
+
the annotation of the abbreviated type. The type of a functor parameter, of a
148
+
recursive module being defined, and a locally abstract type `(type a)` are
149
+
abstract only where they are declared: they stand for another type, so they
150
+
cannot be refined. Only a private abbreviation can declare a subclass of the
151
+
class annotated there, or of a `@typeOf("object")` type, or a public one that
152
+
is a strict instance of the superclass type after expansion, as in the
153
+
phantom type hierarchy
150
154
`@instanceOf("Element") type elementLike<'a> = nodeLike<_element<'a>>`. A
151
-
public `type dog = animal` would make every animal a dog without a coercion.
155
+
public `type dog = animal` would make every animal a dog without a coercion,
156
+
and so would `type dog = phantom<int>` with `type phantom<'a> = animal`.
152
157
153
158
| Declaration | Error | Fixture |
154
159
| --- | --- | --- |
155
160
|`@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`|
156
161
|`@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`|
157
-
|`@instanceOf("Dog") type dog = animal`| A subclass must be a private abbreviation ... |`instance_of_public_subclass.res`|
162
+
|`@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`|
163
+
|`@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`|
158
164
|`@instanceOf("Animal") type t = private dog`| Animal appears twice in this chain of abbreviations ... |`instance_of_class_twice_in_chain.res`|
159
165
|`@instanceOf` on a record or variant |@instanceOf can only be used on abstract types and type abbreviations ... |`runtime_annotation_on_record.res`|
160
166
| both annotations | A type can have either @instanceOf or @typeOf, not both. |`runtime_annotation_conflict.res`|
167
+
| one annotation twice | Duplicate @instanceOf annotation; a type can have only one. |`instance_of_duplicate.res`|
161
168
162
169
The class path is a dot-separated list of identifiers whose first one is not
163
170
a JavaScript keyword. Paths that name no class to recognize values by are
@@ -443,8 +450,10 @@ error.
443
450
444
451
An interface and its implementation must agree on `@unboxed`, on `@tag`, on
445
452
the literal of every nullary case, and on the payload kind of every untagged
446
-
case. They are not compared on the `@as` of cases with a payload (see Known
447
-
bugs).
453
+
case whose kind the interface knows. An unknown payload in the interface is
454
+
its only payload case and is not checked, so it agrees with any payload of
455
+
the implementation (`untagged_hidden_payload_test.res`). They are not
456
+
compared on the `@as` of cases with a payload (see Known bugs).
448
457
449
458
A type for which an interface states a class or `typeof` (rule 5), through
450
459
its own annotation or the type it abbreviates, must state the same one in the
Copy file name to clipboardExpand all lines: tests/analysis_tests/tests/src/expected/CompletionAttributes.res.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -325,7 +325,7 @@ Resolved opens 1 Stdlib
325
325
"detail": "",
326
326
"documentation": {
327
327
"kind": "markdown",
328
-
"value": "The `@instanceOf` decorator states that the values of an abstract type are instances of a global JavaScript class. Such a type can be the payload of an untagged variant case, which is then recognized with `instanceof`, and is never `undefined`, like with `@notUndefined`.\n\nA private abbreviation of another annotated type declares a subclass, so that the subclass case is checked first.\n\nExample usage:\n```rescript\n@instanceOf(\"Blob\")\ntype blob\n\n@instanceOf(\"File\")\ntype file = private blob\n```"
328
+
"value": "The `@instanceOf` decorator states that the values of an abstract type are instances of a global JavaScript class. Such a type can be the payload of an untagged variant case, which is then recognized with `instanceof`, and is never `undefined`, like with `@notUndefined`.\n\nA private abbreviation of another annotated type declares a subclass. A case of the superclass then excludes the instances of a subclass that is a case too, whatever the order of the cases.\n\nExample usage:\n```rescript\n@instanceOf(\"Blob\")\ntype blob\n\n@instanceOf(\"File\")\ntype file = private blob\n```"
[1;31m6[0m [2m│[0m @instanceOf("Date") [1;31mtype date = X.t[0m
8
+
7 [2m│[0m }
9
+
8 [2m│[0m
10
+
11
+
@instanceOf cannot describe the type of a functor parameter, of a recursive module being defined, or a locally abstract type: such a type stands for another one, whose values can be anything.
[1;31m3[0m [2m│[0m @typeOf("object") [1;31mtype o = a[0m
8
+
4 [2m│[0m }
9
+
5 [2m│[0m x
10
+
11
+
@typeOf cannot describe the type of a functor parameter, of a recursive module being defined, or a locally abstract type: such a type stands for another one, whose values can be anything.
0 commit comments