Skip to content

Analyzer doesn't report "Generic function type cannot be used as a type parameter" #33555

@sgrekhov

Description

@sgrekhov

Consider the following code

dynamic forgetType(dynamic d) => d;

typedef T0 = void Function();
typedef T1 = void Function<X>();

void t0Instance() {}
void t1Instance<X>() {}

class ArgumentsBindingTest<X>  {
  ArgumentsBindingTest(X t1) {}
}

main() {
  T0 t0 = t0Instance;
  T1 t1 = t1Instance;
  new ArgumentsBindingTest<T0>(forgetType(t0)); // works
  new ArgumentsBindingTest<T1>(forgetType(t1)); // error
}

This code produces

error: generic function type '<X>() => void' not allowed as type argument of type 'ArgumentsBindingTest<<X>() => void>'
#0      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#1      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

Why function type can be used as a type parameter, but generic function type cannot?

Dart VM version: 2.0.0-dev.63.0 (Fri Jun 15 00:42:43 2018 +0200) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    legacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions