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

It is inconvenient to do pattern matching on "this" #3521

Closed
rrousselGit opened this issue Dec 17, 2023 · 2 comments
Closed

It is inconvenient to do pattern matching on "this" #3521

rrousselGit opened this issue Dec 17, 2023 · 2 comments
Labels
request Requests to resolve a particular developer problem

Comments

@rrousselGit
Copy link

One regular scenario when using extensions is to do pattern matching on this.

For example:

extension on num {
  void example() {
    if (this is int) doSomethingWithInts(this);
    else doSomethingWithDoubles(this);
  }
}

The problem is, this is not promoted after doing type-checks on it. This forces us to either use casts or dereference this.

For example a common pattern I've used is:

final that = this;
if (that is int)  doSomethingWithInts(that);

But this feels redundant. Would it be possible to promote this when doing type checks on it?

@rrousselGit rrousselGit added the request Requests to resolve a particular developer problem label Dec 17, 2023
@halildurmus
Copy link

Duplicate of #1397

Reading the comments, it looks like this was supposed to be part of the promotion of the private final fields feature (#2020).

cc @stereotype441

@rrousselGit
Copy link
Author

Closing since this is a dupp. Sorry I missed it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request Requests to resolve a particular developer problem
Projects
None yet
Development

No branches or pull requests

2 participants