Hi dart-misc,
As I'm migrating to NNBD, I'm adding a! lot! of! exclamation! points!. Many (most?) of these should be inferable automatically IMO. Example:
void greet(String who) {
print("Hello $who");
}
class Test {
String? who = random.nextBool() ? "Bob" : null;
void test() {
if (who != null) {
// Analyzer complains even though who is not null
greet(who);
}
}
}
The call to greet(who) inside the class method test gives an analyzer error.
You get similar errors trying to assign the nullable type to a non-null variable after the null check.
A similar scenario but with a variable declared inside a method does not give any errors:
void test() {
String? who = random.nextBool() ? "Bob" : null;
if (who != null) {
// Analyzer knows this can't be null
greet(who);
}
}
I'm wondering if there is an issue open for this already (hard to find) or if this is intended behavior.
Thanks!
Alec