Skip to content

Passing type-parameterized function to ArgumentError.checkNotNull broken in 2.8.1 #41871

@jonasfj

Description

@jonasfj

I might be using more type-parameters than is useful :)
But I ran into this curious case, and wonder if it's a known regression.

typedef WrapperFn = Future<T> Function<T>(Future<T> Function() fn);

void acceptsWrapper(WrapperFn wrap) async {
  // This works on Dart 2.7.0, but not Dart 2.8.1
  ArgumentError.checkNotNull(wrap);

  // This works fine on both Dart 2.7.0 and 2.8.1
  if (wrap == null) {
    throw ArgumentError.notNull();
  }

  await wrap(() async {
    // Do something async that we want [wrap] to be able to initiate and
    // return the result from, including catching exceptions.
  });
}

void main() => print('hello world');

On dart 2.7.0 it works, but on 2.8.1 I get (before it starts running):

hack.dart:5:17: Error: Generic function type 'Future<T> Function<T>(Future<T> Function())' inferred as a type argument.
 - 'Future' is from 'dart:async'.
Try providing a non-generic function type explicitly.
  ArgumentError.checkNotNull(wrap);
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions