-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).Dart language related items (some items might be better tracked at github.com/dart-lang/language).closed-as-intendedClosed as the reported issue is expected behaviorClosed as the reported issue is expected behavior
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'.
}
}Metadata
Metadata
Assignees
Labels
area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).Dart language related items (some items might be better tracked at github.com/dart-lang/language).closed-as-intendedClosed as the reported issue is expected behaviorClosed as the reported issue is expected behavior