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 gives confusing message when boolean expression has invalid assignment. #40265

Open
dnfield opened this issue Jan 22, 2020 · 4 comments
Labels
analyzer-recovery analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@dnfield
Copy link
Contributor

dnfield commented Jan 22, 2020

bool confusing(Object b) {
  return b is int // Dart analyzer says: missing selector such as '.identifier' or '[0]' - line 2
      && b = 2;   // error is actually here - this should be `==`.
}

void main() {}

Reproduces in dartpad and in IDE. I'd expect to only see an error on line 3 (invalid assignment). I actually see an error on line 2 (in comment), followed by a couple more confusing messages on line 3 :

error
A value of type 'int can't be returned from function 'confusing' because it has a return type of 'bool' - line 2
error
Missing selector such as '.identifier' or '[0]' - line 2
error
The operands of the '&&' operator must be assignable to 'bool' - line 3
error
A value of type 'int' can't be assigned to a variable of type 'bool' - line 3
@dnfield
Copy link
Contributor Author

dnfield commented Jan 22, 2020

The compiler gives a more sensible error, at least for app-jit snapshots:

../../packages/flutter_tools/lib/src/build_system/targets/icon_font_subset.dart:105:25: Error: Can't assign to this.
        && other.family = family
                        ^

@MichaelRFairhurst
Copy link
Contributor

Seems like a very reasonable request. This is a common pattern in other languages and should prob give better output here.

@brianwilkerson

@mit-mit mit-mit added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Jan 22, 2020
@srawlins srawlins added the P3 A lower priority bug or feature request label Nov 24, 2020
@bwilkerson bwilkerson added area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-fasta-recovery and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-recovery labels Aug 9, 2021
@jensjoha
Copy link
Contributor

As indicated in a comment above the CFE gives this error message:

Error: Can't assign to this.
      && b = 2;   // error is actually here - this should be `==`.
           ^

This seems like an analyzer bug to me (which the title also says) so I'll but the "old labels" back.

@jensjoha jensjoha assigned bwilkerson and unassigned jensjoha Aug 20, 2021
@jensjoha jensjoha added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-recovery and removed area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-fasta-recovery labels Aug 20, 2021
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Nov 29, 2021
@srawlins srawlins added the contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) label May 20, 2022
@srawlins
Copy link
Member

srawlins commented Jun 7, 2024

The errors remain today. Very strange errors.

@bwilkerson bwilkerson removed their assignment Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-recovery analyzer-ux area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. contributions-welcome Contributions welcome to help resolve this (the resolution is expected to be clear from the issue) P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants