sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[extension-types] Analyzer sees nullable extension type as non nullable.

Open Quijx opened this issue 1 year ago • 1 comments

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)

Quijx avatar Jan 18 '24 16:01 Quijx

This bug is still present in Dart 3.2.0 stable. Also this issue needs the feature-extension-types tag i think.

Quijx avatar Feb 16 '24 19:02 Quijx

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)

matanlurey avatar Mar 10 '24 22:03 matanlurey

I don't see the error in the analyzer today (the DartPad main channel analyzer does report the error).

eernstg avatar Mar 11 '24 10:03 eernstg

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

parlough avatar Mar 11 '24 10:03 parlough