Files
sdk/pkg/_fe_analyzer_shared/test
Johnni Winther e6e94f79d2 [flow_analysis] Don't promote on invalid type
Flow analysis didn't handle invalid type so non-null promotion would occur on declaration and initialization on erroneous code, leading to warnings about null-aware that is likely valid. For instance

    f(Unresolved o) { // Error: Unresolved is unresolved
      int? i = o.property;
      i?.isEven; // Warning about unnecessary null-aware access
      if (i != null) { // Warning about unnecessary null comparison
        i.isEven;
      }
    }

To handle this fully we need to track invalid nullability (if that is even feasible) but for now we change the default to avoid non-null promotion in such cases.

This *does* change the kind cascading errors/warnings that we produce. For instance

    f(Unresolved o) { // Error: Unresolved is unresolved
      int? i = o.nonNullProperty;
      i.isEven; // Error for access on int?
    }

but since it probably more likely for code to *not* depend on non-null promotion, this should be less noise for the user.

Change-Id: Ia2bc3505a43b52e5151b93a7fee24e95246b4bbc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443320
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2025-08-04 23:45:02 -07:00
..