Reduced test case (see on Dartpad: https://dartpad.dartlang.org/35b1478eec218cf4275a588ff7e679c8)
main() {
var mayBeNull = new DateTime.now().millisecondsSinceEpoch != 1 ? 'foo bar baz' : null;
var nullCoalescedString = mayBeNull ?? (throw new Error());
print(nullCoalescedString.runtimeType); // prints 'String'
print(nullCoalescedString.indexOf('bar')); // prints `null` unexpectedly
}
Replacing (throw new Error()) with other expressions results in correct behavior, with the indexOf line printing 4 instead of null. Expressions I tried:
void function (this is a strong mode error, so it's not completely relevant)nullInterestingly enough, it also happens in this simplified case... (thanks @georgelesica-wf)
main() {
var nullCoalescedString = 'foo bar baz' ?? (throw new Error());
print(nullCoalescedString.runtimeType); // prints 'String'
print(nullCoalescedString.indexOf('bar')); // prints `null` unexpectedly
}
On DartPad today the second example prints 4 instead of null so it looks like this was fixed.
Most helpful comment
On DartPad today the second example prints
4instead ofnullso it looks like this was fixed.