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

Feature request: Warning when intermingling regular methods and cascades #12733

Open
DartBot opened this issue Aug 25, 2013 · 5 comments
Open
Labels
analyzer-ux area-analyzer P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Aug 25, 2013

This issue was originally filed by chris...@gmail.com


In Dart Editor, it would be nice to get a warning when intermingling method cascades and regular method calls (or maybe any other operator).

Consider:

  Map thing = {
    'name': 'Ben Grimm',
    'directed_by': 'John Carpenter'
  };

  var keys = thing
    ..remove('directed_by')
    ..['catchprase1'] = 'It’s clobberin’ time!'
    ..['catchprase2'] = 'Aunt Petunia’s Girdle! What’s happening?'
    .keys;

  print(keys);

The programmer might expect that the keys variable would be assigned to a list, but instead would get a runtime error. So perhaps a warning could be issued in such cases?

The keys property is undefined on the string above, so a warning is already issued by Dart Editor. Still, the cause may not be immediately obvious. Also, there are more obscure cases in which the intended receiver and the actual receiver both support the same method call (e.g. when working with Futures).

Dart VM version: 0.6.19.0_r26297 (Sat Aug 17 07:12:38 2013) on "linux_x64"

@bwilkerson
Copy link
Member

Added this to the Later milestone.
Removed Type-Defect, Priority-Unassigned labels.
Added Type-Enhancement, Priority-Medium, Area-Analyzer, Triaged labels.

@bwilkerson
Copy link
Member

We are required to generate the current warning, and I don't think we want the general rule, but I think we should look at improving the error message to indicate a possible solution.


Added Analyzer-UX label.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@srawlins
Copy link
Member

Just looking at old issues, drive by comment:

I can see adding some intelligence to various error messages targeted at where users are commonly surprised by the precedence rules. Here's another example:

void f(Future f1, Future f2) async {
  await 1 == 2 ? f1 : f2;
}

There error here is that you cannot await an int. Huh? 🤔 Oh this is equivalent to ((await 1) == 2) ? f1 : f2.

You can imagine in both the cascade example, and this await example: check the parent expression. Does the user think that this property access, or await expression, is applying to its own parent?

@srawlins srawlins added P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-ux area-analyzer P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants