Skip to content

Commit 1b56643

Browse files
committed
fix(types): always use type specifier for "other" in elsa-type-accept
This is necessary to properly resolve cases where "any type" is matched with "any form" or "any variable". Since the dispatch picks by specificity on the first argument, not specifying the second one always picked for example "const type and anything" over "type and form" to resolve to "type and type".
1 parent 3ecb96a commit 1b56643

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

elsa-types.el

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Uses special rules for `elsa-type-mixed'.
174174
(cl-defmethod elsa-type-get-return ((this elsa-type))
175175
this)
176176

177-
(cl-defmethod elsa-type-accept ((this elsa-type) other &optional explainer)
177+
(cl-defmethod elsa-type-accept ((this elsa-type) (other elsa-type) &optional explainer)
178178
"Test if THIS type accepts OTHER.
179179
180180
Accepting in this context means that OTHER can be assigned to
@@ -231,7 +231,7 @@ empty.")
231231
(cl-defmethod elsa-type-describe ((_this elsa-type-empty))
232232
"empty")
233233

234-
(cl-defmethod elsa-type-accept ((this elsa-type-empty) other &optional explainer)
234+
(cl-defmethod elsa-type-accept ((this elsa-type-empty) (other elsa-type) &optional explainer)
235235
(if (elsa-type-composite-p other)
236236
(elsa-type-is-accepted-by other this explainer)
237237
(elsa-with-explainer explainer
@@ -282,7 +282,7 @@ of them.")
282282
(oset new types types)
283283
new))
284284

285-
(cl-defmethod elsa-type-accept ((this elsa-intersection-type) other &optional explainer)
285+
(cl-defmethod elsa-type-accept ((this elsa-intersection-type) (other elsa-type) &optional explainer)
286286
(elsa-with-explainer explainer
287287
(elsa--fmt-explain-type-0-does-not-accept-type-1
288288
(elsa-tostring this) (elsa-tostring other))
@@ -339,7 +339,7 @@ because the actual type can be any of them.")
339339
(oset new types types)
340340
new))
341341

342-
(cl-defmethod elsa-type-accept ((this elsa-sum-type) other &optional explainer)
342+
(cl-defmethod elsa-type-accept ((this elsa-sum-type) (other elsa-type) &optional explainer)
343343
(cond
344344
((elsa-type-composite-p other)
345345
(elsa-type-is-accepted-by other this explainer))
@@ -396,7 +396,7 @@ type and none of the negative types.")
396396
(oset new negative negative)
397397
new))
398398

399-
(cl-defmethod elsa-type-accept ((this elsa-diff-type) other &optional explainer)
399+
(cl-defmethod elsa-type-accept ((this elsa-diff-type) (other elsa-type) &optional explainer)
400400
(elsa-with-explainer explainer
401401
(elsa--fmt-explain-type-0-does-not-accept-type-1
402402
(elsa-tostring this) (elsa-tostring other))
@@ -845,7 +845,7 @@ then this is a supertype of other."
845845
(mapconcat 'elsa-type-describe (oref this args) " ")
846846
(elsa-type-describe (oref this return))))
847847

848-
(cl-defmethod elsa-type-accept ((this elsa-function-type) other &optional explainer)
848+
(cl-defmethod elsa-type-accept ((this elsa-function-type) (other elsa-type) &optional explainer)
849849
(if (elsa-type-composite-p other)
850850
(elsa-type-is-accepted-by other this explainer)
851851
(if (elsa-function-type-p other)
@@ -1035,7 +1035,7 @@ predefined value.")
10351035
(cl-defmethod elsa-type-describe ((this elsa-const-type))
10361036
(format "(const %S)" (oref this value)))
10371037

1038-
(cl-defmethod elsa-type-accept ((this elsa-const-type) other &optional explainer)
1038+
(cl-defmethod elsa-type-accept ((this elsa-const-type) (other elsa-type) &optional explainer)
10391039
"The const type is different from readonly in that a readonly
10401040
type can never be assigned to but a const type is only a
10411041
narrowing of a type to a concrete value from the type's domain.
@@ -1063,7 +1063,7 @@ to this value."
10631063
It wraps any other type and makes the form or variable
10641064
unassignable.")
10651065

1066-
(cl-defmethod elsa-type-accept ((this elsa-readonly-type) other &optional explainer)
1066+
(cl-defmethod elsa-type-accept ((this elsa-readonly-type) (other elsa-type) &optional explainer)
10671067
"Check if this readonly type accept other type.
10681068
10691069
The acceptance does not depend on the readonly status. Here we
@@ -1100,7 +1100,7 @@ trying to analyse 'nil, which is not a valid type or form."
11001100
(when-let ((class (get (oref this name) 'elsa-defstruct)))
11011101
(elsa-get-slot class name)))
11021102

1103-
(cl-defmethod elsa-type-accept ((this elsa-struct-type) other &optional explainer)
1103+
(cl-defmethod elsa-type-accept ((this elsa-struct-type) (other elsa-type) &optional explainer)
11041104
(cond
11051105
((elsa-type-composite-p other)
11061106
(elsa-type-is-accepted-by other this explainer))
@@ -1142,7 +1142,7 @@ trying to analyse 'nil, which is not a valid type or form."
11421142
(when-let ((class (get (oref this name) 'elsa-defclass)))
11431143
(elsa-get-slot class name)))
11441144

1145-
(cl-defmethod elsa-type-accept ((this elsa-class-type) other &optional explainer)
1145+
(cl-defmethod elsa-type-accept ((this elsa-class-type) (other elsa-type) &optional explainer)
11461146
(cond
11471147
((elsa-type-composite-p other)
11481148
(elsa-type-is-accepted-by other this explainer))
@@ -1203,7 +1203,7 @@ symbol represents. During checking, we will try to forward to
12031203
(cl-defmethod elsa-type-describe ((this elsa-type--cl-ref))
12041204
(format "(cl-ref %s)" (oref this name)))
12051205

1206-
(cl-defmethod elsa-type-accept ((this elsa-type--cl-ref) other &optional explainer)
1206+
(cl-defmethod elsa-type-accept ((this elsa-type--cl-ref) (other elsa-type) &optional explainer)
12071207
(elsa-type-accept (elsa-type--resolve-cl-ref this) other explainer))
12081208

12091209
(cl-defmethod elsa-type-accept ((this elsa-class-type) (other elsa-type--cl-ref) &optional explainer)

0 commit comments

Comments
 (0)