Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Dart does not throw compile time error when wrong type is assigned to a variable using the if null operator (??) #36964
Dart VM version: 2.3.0-dev.0.5.flutter-a1668566e5 (Tue Apr 30 20:35:41 2019 +0200) on "macos_x64"
Dart does not throw compile time error when wrong type is assigned to a variable if you use the "if null" operator. Following example compiles without error and then throws a runtime error:
I believe this is a classical example of the way our unification interacts with implicit downcasts.
The static type of
With non-nullable types, the
Until then, the analyzer option implicit-casts can warn you about all downcasts, which will catch cases like this ... and a lot of other downcasts which are probably perfectly fine.