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

Recursive getter does not throw warning when using pattern matching #4913

Open
victor-tinoco opened this issue Mar 14, 2024 · 2 comments
Open
Labels
false-negative P3 A lower priority bug or feature request set-recommended Affects a rule in the recommended Dart rule set type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@victor-tinoco
Copy link

So, if you declare a class with a getter, like this:

class A {
  String get name {
    return switch (this) {
      // Notice that while declaring the name getter, I can access it here without warning.
      A(name: final name) => name,
    };
  }
}

The recursive_getters rule should warn this case, shouldn't it? Pattern matching does allow you to refer to the getter you're declaring (on its declaration scope body). The same occurs when you create a getter through an extension.

I fell in this case because of my copilot, when I tried to build it by running the tests, it just crashed with a non-descriptive error, probably because it is like a recursion with no break. It should not be allowed since it always falls in a runtime error.

Obs.: Re-opening it from dart-lang/language#3652.

@github-actions github-actions bot added the set-recommended Affects a rule in the recommended Dart rule set label Mar 14, 2024
@lrhn
Copy link
Member

lrhn commented Mar 16, 2024

It's not always a mistake to invoke the same getter, of it's not on the same object.
Fx:

  Node get last { 
    return switch (this.next) {
      // Notice that while declaring the name getter, I can access it here without warning.
      A(last: final last) => last,
      _ => null,
    };
  }

Same getter called, but not on the same object.

So this issue requires not just figuring out that the same getter is office again, but also determining whether it's definitely, or possibly, on the same object.
That's not always going to be possible.

@pq pq added the P3 A lower priority bug or feature request label Mar 18, 2024
@victor-tinoco
Copy link
Author

It's not always a mistake to invoke the same getter, of its bout on the same object. Fx:

  Node get last { 
    return switch (this.next) {
      // Notice that while declaring the name getter, I can access it here without warning.
      A(last: final last) => last,
      _ => null,
    };
  }

Same getter called, but not on the same object.

So this issue requires not just figuring out that the same getter is office again, but also determining whether it's definitely, or possibly, on the same object. That's not always going to be possible.

Yea, we might apply this only when using switch for this, for example. I mean, we have a linter with exactly this proposal recursive_getters, it looks like it surely might cover it.

@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-negative P3 A lower priority bug or feature request set-recommended Affects a rule in the recommended Dart rule set type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants