Skip to content

Negative type constraint #46114

@mleonhard

Description

@mleonhard

Dart currently lets us write

T someFunc<T extends Object>(T Function() f) {...}

I repeatedly make the mistake of passing Future<T> Function() to a function that expects T Function(). These mistakes often cause runtime errors. I wish to prevent such errors with a type constraint that means "T does not extend Future". Proposed syntax:

T someFunc<T extends Object + !Future>(T Function() f) {...}

A linter warning would also solve the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-pkg-metaIssues related to package:metatype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions