Closed
Description
In these cases we should be able to infer that the type cannot be null, however the current implementation raises a compile error:
class A<T> {
final T value;
A(this.value);
}
void main() {
int? n = 3;
int n2 = n == null ? 3 : n + 2; // as intended
if (n != null) {
int n2 = n; // as intended
}
A<int?> a = A(3);
int b = a.value == null ? 3 : a.value + 2; // error: Operator '+' cannot be called on 'int?' because it is potentially null
if (a.value != null) {
int b = a.value; // error: A value of type 'int?' can't be assigned to a variable of type 'int'.
}
}