Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type recognizing after null check block #59894

Closed
ChaserVasya opened this issue Jan 13, 2025 · 3 comments
Closed

Wrong type recognizing after null check block #59894

ChaserVasya opened this issue Jan 13, 2025 · 3 comments
Labels
closed-as-intended Closed as the reported issue is expected behavior

Comments

@ChaserVasya
Copy link

Snippet

extension NotEmptyOrThrowTExtension<String> on String? {
  String notEmptyOrThrow(Object exception) {
    final self = this;
    if (self == null) {
      throw exception;
    }
    if (self.isEmpty) {
      return self;
    }
    return self;
  }
}

Actual behavior

Снимок экрана 2025-01-13 в 19 16 07

Expected behavior

isEmpty is recognized.

Version

Dart SDK version: 3.5.4 (stable) (Wed Oct 16 16:18:51 2024 +0000) on "macos_arm64"

@ChaserVasya ChaserVasya added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 13, 2025
@mraleph mraleph added closed-as-intended Closed as the reported issue is expected behavior and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Jan 13, 2025
@mraleph
Copy link
Member

mraleph commented Jan 13, 2025

For those curious: extension NotEmptyOrThrowTExtension<String> on String? means that String is actually a type parameter name shadowing String class from dart:core (i.e. it is the same as extension NotEmptyOrThrowTExtension<T> on T?) - hence the error. Removing <String> would fix it.

I think at some point we considered adding code to the analyzer to warn about such shadowing, because people periodically fall into this trap) but probably never got to it.

@eernstg
Copy link
Member

eernstg commented Jan 13, 2025

https://dart-review.googlesource.com/c/sdk/+/381841 will change avoid_types_as_parameter_names such that this kind of shadowing is reported. Internal code is being adjusted such that the change won't be breaking inside Google.

@ChaserVasya
Copy link
Author

I solved this by removing :D
And I close issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

3 participants