Intersection type soundness issue #56050
Labels
analyzer-spec
Issues with the analyzer's implementation of the language spec
area-dart-model
Use area-dart-model for issues related to packages analyzer, front_end, and kernel.
P2
A bug or feature request we're likely to work on
soundness
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Consider the following program:
This program is accepted with no diagnostics by the analyzer. However, it violates soundness because
foo
is invoked with an argument of typeObject
which is passed on toid
, and the body ofid
invokesisEven
on that object.The core reason for this soundness violation is that the invocation
id(y)
is inferred to have a type argument which is reified asY
, but we cannot proveY <: int
, and this means that the invocation ofid
is unsound.It seems likely that this is allowed to happen because type inference of the invocation of
id
uses the static type of the actual argument, namelyY & int
, and this yields an actual type argument that does satisfy the declared bound, as if the invocation had been of the formid<Y & int>(y)
. This explanation could be wrong, but in that case it is not easy to see why no bound violation error occurs at the invocation ofid
(or, rather, an error which reports that type inference forid(y)
failed).This is not possible, of course, because
Y & int
cannot be reified. So it is erased toY
, and that is what is passed as the actual type argument at run time. It is the erasure that introduces the type soundness violation (or, rather, the fact that no checks are performed after the erasure).The CFE does not have this soundness issue, it correctly reports that inference of an actual type argument to
id
fails.The text was updated successfully, but these errors were encountered: