I have following piece of code:
import 'dart:math';
void main() {
A? a = new Random().nextInt(2) == 0 ? new A() : null;
if (a?.b ?? false) {
// Following line gives error:
// The argument type 'A?' can't be assigned to the parameter type 'A'.
someFunction(a);
}
}
class A {
bool b = true;
}
someFunction(A a) {}
It throws following error on line someFunction(a); inside if clause:
The argument type 'A?' can't be assigned to the parameter type 'A'.
I had assumed that if variable 'a' is null the line inside if clause would never be executed. Thus 'a' should have been type promoted to 'A' instead of 'A?'.
Please help me find what I'm missing here.