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

Analyzer reports invalid matches for valid type checks on extension types #53725

Closed
Tracked by #49732
jakemac53 opened this issue Oct 10, 2023 · 1 comment
Closed
Tracked by #49732
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-extension-types Implementation of the extension type feature P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@jakemac53
Copy link
Contributor

See the following example, using a private extension type to model a union type:

void main() {
  foo(1.asIntOrString);
  foo('1'.asIntOrString);
}

void foo(_IntOrString intOrString) {
  switch(intOrString) {
    case int():
      print('int!');
    case String():
      print('String!');
    default:
      throw StateError('Something else! ${intOrString.runtimeType}');
  }
}

extension type _IntOrString(Object _) {}

extension StringAsIntOrString on String {
  _IntOrString get asIntOrString => _IntOrString(this);
}

extension IntAsIntOrString on int {
  _IntOrString get asIntOrString => _IntOrString(this);
}
@jakemac53 jakemac53 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. feature-extension-types Implementation of the extension type feature labels Oct 10, 2023
@scheglov scheglov self-assigned this Oct 17, 2023
@scheglov scheglov added the P1 A high priority bug; for example, a single project is unusable or has many test failures label Oct 17, 2023
@scheglov
Copy link
Contributor

copybara-service bot pushed a commit that referenced this issue Oct 18, 2023
…ched type.

Bug: #53725
Change-Id: Ia9ea1b964288f05a19b23562a5c1e08e8dff5aa0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330981
Reviewed-by: Samuel Rawlins <srawlins@google.com>
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. feature-extension-types Implementation of the extension type feature P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

2 participants