Open
Description
By some reason Dart cannot be sure that the method argument is not null if the argument is used in a closure. Property 'isEven' cannot be accessed on 'int?' because it is potentially null
void main() {
foo(1);
}
void foo(int? nullable) {
Future.delayed(Duration(seconds:0)).then((_)
{
if (nullable == null) {
nullable = 5;
}
if (nullable == null) {
return;
}
print(nullable.isEven);
});
}
In this case, as far as I undestand, there's no chance that the 'nullable' argument suddenly becomes nullable after the 1st check, because it's just a method argument, not class field.
The problem is not reproduced if remove the first check.
Dart 2.12.2
Windows