[analyzer] A function literal can have a type where an intersection type occurs #52127
Labels
area-dart-model
Use area-dart-model for issues related to packages analyzer, front_end, and kernel.
dart-model-analyzer-spec
Issues with the analyzer's implementation of the language spec
P3
A lower priority bug or feature request
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Consider the following program (created by @lrhn and shown here):
This program gives rise to the following compile-time error from the analyzer (742612d) at the invocation of
foo
in line 5:This makes sense because
v
has the promoted typeT & num
, and horizontal type inference dictates that the type of the function literal is computed in a phase after the phase where the 2nd parameter and argument (v
) are processed, such that the choiceV == T & num
can be taken into account.However, an intersection type like
T & num
should never occur as part of the type of a function object. It should only occur as a type at the top level, and it should never be reified. The fact that the error message mentions assignability toT Function(T)
implies that the invocation off
is taken to get the type argumentT
(which is fine), but, apparently, the erasure ofT & num
toT
did not take place during horizontal inference, and hence it ended up in the function type.The rules about how to obtain a reifiable type from a given intersection type are not fully specified. Typically, so far, the implementations have erased
X & B
toX
. A discussion about this topic is ongoing in #56028. It is not expected that these discussions will change the fact that intersection types cannot be reified, but it is possible thatX & B
could be erased toB
in some situations. (For example, it would be a useful choice in the example above.)The text was updated successfully, but these errors were encountered: