Skip to content

Analyzer gives confusing message when boolean expression has invalid assignment. #40265

@dnfield

Description

@dnfield
Contributor
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

Activity

dnfield

dnfield commented on Jan 22, 2020

@dnfield
ContributorAuthor

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

MichaelRFairhurst commented on Jan 22, 2020

@MichaelRFairhurst
Contributor

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

@brianwilkerson

added
P3A lower priority bug or feature request
on Nov 24, 2020
jensjoha

jensjoha commented on Aug 20, 2021

@jensjoha
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.

added
type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)
on Nov 29, 2021
added
contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)
on May 20, 2022
srawlins

srawlins commented on Jun 7, 2024

@srawlins
Member

The errors remain today. Very strange errors.

removed their assignment
on Jun 10, 2024
added
area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
and removed on Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestanalyzer-recoveryarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)devexp-uxtype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @srawlins@MichaelRFairhurst@bwilkerson@dnfield@mit-mit

        Issue actions

          Analyzer gives confusing message when boolean expression has invalid assignment. · Issue #40265 · dart-lang/sdk