Kernel output contains an overly broad type when lowering an expression that's unnecessarily null-aware due to null shorting #59636
Labels
area-front-end
Use area-front-end for front end / CFE / kernel format related issues.
cfe-encodings
Encoding related CFE issues.
cfe-optimizations
CFE optimizations
front-end-expression-compilation
Consider the following null-aware expression (taken from
pkg/front_end/testcases/nnbd/null_shorting.dart
):Where
n1
has typeClass1?
andClass1.nonNullable1Method
has return typeClass1
. Note that the second?.
is not necessary (because, thanks to null shorting, it only executes whenn1 != null
); therefore it should, in principle, be possible to optimize it to.
during compilation.The kernel generated for this expression is (line breaks added for clarity):
Although this has correct runtime semantics, the type of
#t81
is unnecessarily broad. It could beself::Class1
instead ofself::Class1?
, since the initializer expression is the value returned bynonNullable1Method
, which has return typeClass1
.I suspect that if the type of
#t81
were corrected, it would improve the chances of back-ends detecting that the null check#t81 == null
is unnecessary (and thus performing the correct optimization).The text was updated successfully, but these errors were encountered: