Skip to content

int doesn't extend Comparable<int> #43763

Closed
@znjameswu

Description

@znjameswu

This is an old issue since Dart 1 and doesn't seem to have been fixed. #8741

This behavior is preventing the below API patterns from being efficiently implemented.

extension ListExtension<T> on List<T> {
  void sortBy<T2 extends Comparable<T2>>(T2 Function(T element) f) {
    this.sort((a, b) => f(a).compareTo(f(b)));
  }
}

Trying to invoke this function

[1].sortBy((x) => x);

will cause error: int doesn't extend Comparable<int>

We need to change generics parameter to num at every invocation site.

[1].sortBy<num>((x) => x);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.library-coretype-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