Closed kikofernandez closed 1 year ago
However, the following example accepts an ill-typed program.
It's an ill-typed program in strict mode - and in strict mode it would be rejected (eqWAlizer would complain that function type_dyn
doesn't have a spec).
In gradual mode (the default mode for now), function type_dyn would be seen by eqWAlizer as:
-spec type_dyn(eqwalizer:dynamic()) -> eqwalizer:dynamic().
type_dyn(X) -> 42.
So, answering your question, eqWAlizer (for now) follows the first design you described.
Hi! The documentation states "subtype" and "supertype" for the sake of simplicity, but under the hood, the relation used to check the type of applications is actually consistent subtyping (as defined in Gradual Typing for Objects). It is, of course, not defined as transitive for the reasons you mentioned.
EqWAlizer does not perform any kind of inference for unspecced functions: it assumes type ?
for every parameter, and type ?
for the result. Which means that in your example, type_dyn
is given type ? -> ?
, which corresponds to your first case.
And, as you said, since ?
is a consistent-subtype of string()
, the program is accepted.
There is actually a "true" subtyping relation used in parts of eqWAlizer, mostly for computing union types and for occurrence typing. For this subtyping relation, ?
is only a subtype of itself (and term()
), so that this relation is transitive. It is particularly useful to ensure that, for example ? | atom()
is not equivalent to ?
and thus not a consistent subtype of, say, number()
.
Thanks for both answers, specially to @VLanvin for pointing out more details so that I can follow what happens under the hood :)
Hi, the reference docs (https://github.com/WhatsApp/eqwalizer/blob/main/docs/reference/modes.md) state:
If this were to be true, subtyping is usually a transitive relation where one can
bool <: ? <: int
, which could accept almost any program (Section 4 of Gradual Typing for Objects).Would it be possible to know which notion of subtyping (and/or type consistency rules) your project uses? Thanks
Example:
The example below is correctly reported as an error
However, the following example accepts an ill-typed program.
We know that under the assumption that Γ is the environment:
I am trying to understand if the type checker sees
type_dyn : ? -> ?
or astype_dyn : ? -> number()
.type_dyn : ? -> ?
) I guess that the rule that follows to "match"?
andstring()
is? <: string()
so the type checker accepts the program.type_dyn : ? -> number()
) one could apply subsumption to makenumber() <: ?
and then? <: string()
because the subtyping relation by default is transitive, which would accept the program even when it is ill-formed.Question: Which of the two (or something else) type checking designs does eqwalizer follow?