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

PATTERN_NEVER_MATCHES_VALUE_TYPE not raised for record patterns #53405

Closed
shilangyu opened this issue Aug 31, 2023 · 1 comment
Closed

PATTERN_NEVER_MATCHES_VALUE_TYPE not raised for record patterns #53405

shilangyu opened this issue Aug 31, 2023 · 1 comment
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@shilangyu
Copy link
Contributor

Tested on newest master 3.2.0-77.0.dev.

When performing a pattern match using a record pattern, the diagnostic warning PATTERN_NEVER_MATCHES_VALUE_TYPE will not be raised when expected to.

Examples

When shape of a record does not match:

void f(({int a, int b}) x) {
  // no pattern_never_matches_value_type raised
  if (x case (:int f1, :int f2,)) {}
}

In fact the type of the matched upon value does not matter, the warning will not be raised even for the following:

void f(int x) {
  // no pattern_never_matches_value_type raised
  if (x case (:String hello)) {}
}

However when the record is used as a type pattern, the warning is correctly raised:

void f(({int f1,}) x) {
  // warning is raised
  if (x case ({int f1, int f2,}) _) {}
}

Finally, this doesn't seem to be a general problem with destructuring patterns, because for example a list pattern does raise the warning:

void f(int x) {
  // warning is raised
  if (x case [String t]) {}
}

Potentially related previous work: #52103

If this is not expected and needs a fix, I would love to dedicate a weekend to dig into this if outside contribution will be welcome here.

@scheglov scheglov self-assigned this Aug 31, 2023
@scheglov
Copy link
Contributor

@a-siva a-siva added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 31, 2023
@scheglov scheglov closed this as completed Sep 1, 2023
copybara-service bot pushed a commit that referenced this issue Sep 1, 2023
…rns.

Bug: #53405
Change-Id: I139fc620f10f18ab2b44b806ab24fa09e9956f61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323685
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
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.
Projects
None yet
Development

No branches or pull requests

3 participants