sdk
sdk copied to clipboard
[extension-types] Analyzer sees nullable extension type as non nullable.
The analyzer shows no errors for the following code:
void main() {
bar(null);
}
void bar(Foo? foo) {
print(foo.i);
}
extension type Foo(int i) {}
However when running it, the following error is correctly shown by the CFE:
bin/dart_bug_nullable_extension_type.dart:6:13: Error: Property 'i' cannot be accessed on 'Foo?' because it is potentially null.
Try accessing using ?. instead.
print(foo.i);
^
The expectation would be that the analyzer disallows foo.i in the print aswell.
This happens on Dart 3.2.3 as well as on the current master channel in dartpad.dev (3.3.0-279.0.dev)
This bug is still present in Dart 3.2.0 stable. Also this issue needs the feature-extension-types tag i think.
I'd encourage thinking about this as P1, as the extension types feature seems incomplete without it.
(As mentioned elsewhere, yes the compiler will catch this)
I don't see the error in the analyzer today (the DartPad main channel analyzer does report the error).
Yep. I believe https://github.com/dart-lang/sdk/commit/421ffd331a1262e0bd23ea69298c3cd52718c04f fixed this which is now in the latest dev and main channel releases :D