Skip to content

Unable to infer closure parameter type #60330

@Taoduhui

Description

@Taoduhui
typedef CallbackA<T extends MyClassBase> = void Function(MyClassB<T> s);

abstract class MyClassBase{

}

class MyClassA<T> extends MyClassBase{
  T value;

  MyClassA({
    required this.value,
    List<CallbackA<MyClassA<T>>> callbacks = const [],
  });
}

class MyClassB<T extends MyClassBase> {}

var a = MyClassA(
  value: 1,
  callbacks:[
    (c /* MyClassB<MyClassA<Object?>> */){
      
    }
  ] // List<void Function(MyClassB<MyClassA<int>>)>
);

var b = MyClassA<int>(
  value: 1,
  callbacks:[
    (c /* MyClassB<MyClassA<int>> */){
      
    }
  ] // List<void Function(MyClassB<MyClassA<int>>)>
);

In scenario a, the callback parameter is inferred as Object?, even though the callbacks property has the correct type.

the correct type can be inferred if the generic type for MyClassA is explicitly declared.

Metadata

Metadata

Labels

area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-inferenceImplementation of type inferencesoundnesstype-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

Issue actions