Skip to content

Migration tool sometimes suggests .whereOrNull where it shouldn't #49103

@stereotype441

Description

@stereotype441

Consider the following code:

f<U>(Iterable<U> it) => it.where((s) => s != null);

The migration tool changes this to:

import 'package:collection/collection.dart' show IterableNullableExtension;

f<U>(Iterable<U> it) => it.whereNotNull();

However, this doesn't work because the signature of whereNotNull is:

extension IterableNullableExtension<T extends Object> on Iterable<T?> {
  Iterable<T> whereNotNull() => ...;
}

When the type system tries to solve for a substitution T=... that makes the extension apply, it gets T=U, but that doesn't work because U is not a subtype of Object.

So the migration tool shouldn't change the where to whereNotNull in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-migration (deprecated)Deprecated: this label is no longer actively used (was: issues with the `dart migrate` tool).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions