Skip to content

Bad "create function 'foo'" result; Given option to add a null check when it doesn't makes sense #61056

Open
@jensjoha

Description

@jensjoha

Say I have this:

void main() {
  int combined = 0;
  combined += foo();
  combined += bar();
  print(combined);
}

Both foo and bar have red squigglies because they are undefined.
Luckily I can get help, so in the quick fix menu for foo I choose "Create function 'foo'" and this code is inserted:

num foo() {
}

This leaves me with another error on that line though: "A value of type 'num' can't be assigned to a variable of type 'int'."
Why wasn't the added code

int foo() {
}

?

Asking for quick fixes on bar I notice that I'm also given the option to "Add a null check (!)" which doesn't really make sense. Doing it (so I now have combined += bar()!; and still the same error of bar being undefined) I still have that option and picking it unsurprisingly gives me combined += bar()!!; and I can just keep going. I also had this option on foo btw.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions