Skip to content

Type-inference error not equating dynamic and Object #30829

Closed
@floitschG

Description

@floitschG

/cc @leafpetersen

Take the following code:

void foo(void Function(Object) f) {  }

void main() {
  var f = (dynamic x) { };
  foo(f);
}

This should work: f has type dynamic -> void, or as the inference currently infers: dynamic -> Null.

However I get the following error message:

The argument type '(dynamic) → Null' can't be assigned to the parameter type '(Object) → void'.

I can remove this error message in two ways:

  1. change from dynamic to Object (which should be the same thing).
  2. change the return type from Null to void (by making it a nested function).

Neither should be necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions