Closed T4rk1n closed 2 months ago
Yes, a type error can cause downstream type errors. If you fix the initial type error, any errors that result from the first one will also go away.
In this particular case, the reason you're seeing the secondary error is that the bidirectional type inference logic sees that there is an error attempting to coerce the expression A(a=1)
to type S
, so it falls back on regular inference rules, which evaluate the type A
. That results in the list being evaluated as type list[S | A]
(which is equivalent to list[A]
), and this type is not assignable to list[S]
because of invariance.
In this particular case, the reason you're seeing the secondary error is that the bidirectional type inference logic sees that there is an error attempting to coerce the expression A(a=1) to type S, so it falls back on regular inference rules, which evaluate the type A. That results in the list being evaluated as type list[S | A] (which is equivalent to list[A]), and this type is not assignable to list[S] because of invariance.
But then why all instances of A that don't have an error also get flagged?
The second screenshot shows inconsistent behavior with the above statement, as now only the C is flagged.
Consider the following classes:
if you then have an invalid type as
a
inb
, the whole list will be highlighted as error, making finding the actual error difficult:If you add an invalid type to the list, only the actual errors are highlighted, which is the desired behavior: