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

Dart analyzer not analyzing correct after If(variable case class) #56914

Closed
abikko opened this issue Oct 18, 2024 · 2 comments
Closed

Dart analyzer not analyzing correct after If(variable case class) #56914

abikko opened this issue Oct 18, 2024 · 2 comments
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@abikko
Copy link

abikko commented Oct 18, 2024

  • Dart version and tooling diagnostic info (dart info)
    Screenshot 2024-10-18 at 14 05 18

  • Whether you are using Windows, macOS, or Linux - macOS

  • Whether you are using Chrome, Safari, Firefox, Edge - doesn't matter

Hello Dart team!

I have a problem, I searched the probably existing issues, but didn't find anything relating to this issue.

So, consider example, we have a sealed class with child classes like in screenshot below:
Screenshot 2024-10-18 at 14 12 57

And if we will write code like this:

Screenshot 2024-10-18 at 14 30 59

Dart analyzer will warn us that testor is A, not B after checking pattern.
Screenshot 2024-10-18 at 14 31 38

@dart-github-bot
Copy link
Collaborator

Summary: The Dart analyzer incorrectly identifies the type of a variable after a pattern matching if statement, reporting it as the original type instead of the type matched in the if condition. This leads to incorrect warnings and potential runtime errors.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Oct 18, 2024
@abikko abikko closed this as completed Oct 18, 2024
@mraleph
Copy link
Member

mraleph commented Oct 18, 2024

It should be case B() not case B then it will work as you want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants