Skip to content

Assignment errors on complex Function/Record types are unreadable #60543

Open
@rrousselGit

Description

@rrousselGit

Here's an error I came across recently:

Image

Where the code is a tearOff:

Class(providerFactory: AnotherClass.new)

It goes to say that this error message is pretty much useless due to how much information overload there is.

The root of the issue IMO is: For Functions/Records, just logging the entire type isn't enough.

I think it would be massively helpful if:

  • The type was formatted to span over multiple lines (by respecting dart_style!)
  • Whatever causes the assignment error should be highlighted using diff or some special colour

Here's an example of what I think

Consider:

void fn(int a, {String? b, required int c, double? d, bool? e}) {}

void Function(
  int a, {
  String? b,
  int? c,
  double? d,
  bool? e,
  Object? f,
}) cb = fn;

The current error message is:

A value of type 'void Function(int, {String? b, int? c, double? d, bool? e})' can't be assigned to a variable of type 'void Function(int, {String? b, int c, double? d, bool? e, Object? f})'.
Try changing the type of the variable, or casting the right-hand type to 'void Function(int, {String? b, int c, double? d, bool? e, Object? f})'

I think it'd be more more readable if we instead had:

Invalid assignment error.

Expected:
void Function(int a, {String? b, int? c, double? d, bool? e})

But got:
void Function(
  int a, {
  String? b,
  required int c,
  double? d,
  bool? e,
  Object? f,
})

Where the difference is:
void Function(
  int a, {
  String? b,
- int? c,
+ required int c,
  double? d,
  bool? e,
+  Object? f,
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-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