Skip to content

Generic function type mismatch: type '(Subtype) => ReturnType' is not a subtype of type '((Supertype) => ReturnType)?' #55286

Closed
@maRci002

Description

@maRci002
class A {}

class A2 extends A {}

class B<T extends A> {
  const B({this.method});

  final num Function(T)? method;
}

void main() {
  final List<B<A>> list = [
    B<A2>(method: (A2 data) => 1),
    const B(),
  ];

  final mention = list[0];
  print(mention);

  var method = mention.method;
  print(method);
}

Output:

Instance of 'B<A2>'
Unhandled exception:
type '(A2) => int' is not a subtype of type '((A) => num)?'
#0      main (package:mark_content/asd.dart:20:24)
#1      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#2      _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

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