Skip to content

make int implement Comparable<int>? #8741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sigmundch opened this issue Feb 23, 2013 · 5 comments
Closed

make int implement Comparable<int>? #8741

sigmundch opened this issue Feb 23, 2013 · 5 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.

Comments

@sigmundch
Copy link
Member

I'm not sure what's the right fix for this. I want to use:

SplayTreeMap<int, X>

but I get an error in checked mode that 'int' is not a 'Comparable<int>' (currently SplayTreeMap expects 'K extends Comparable<K>')

I can work around this easily by using 'num' as the type of my keys, but I think there is something here that should be fixed. Either we want to make
'int' implements 'Compatable<int>', or relax the type constraint in SplayTreeMap, for instance to expect a K extends Comparable, but not necessarily Comparable<K>?

@jmesserly
Copy link

This seems like a bug in subtype tests? A class that implements Comparable<num> should be Comparable<int>.

Uh, even stranger, Comparable seems to be non-generic:
https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/lib/core/comparable.dart?r=13806

@sigmundch
Copy link
Member Author

true, maybe it's a bug in subtype tests?

Note: seems like you had a link to a very old revision, it was added this past week:

https://code.google.com/p/dart/source/browse/branches/bleeding_edge/dart/sdk/lib/core/comparable.dart

CC'ng Gilad to get his opinion.


cc @gbracha.

@jmesserly
Copy link

I was confusing assignment compatibility with subtype tests.
It is strange that int does not implement Comparable&lt;int>, however.

@lrhn
Copy link
Member

lrhn commented Feb 25, 2013

It is a problem.
We can "solve" this by doing
 class int extends num implements Comparable<int>, Comparable<num>
but it will still break for other publicly visible classes that are comparable to a superclass of themselves.

@lrhn
Copy link
Member

lrhn commented Mar 15, 2013

The problem is "solved" by changing the typing requirement on SplayTreeMap.
It now accepts any class, and takes a comparator as argument. If the comparator is omitted, it defaults to Comparable.compare, which means that the type must implement compareTo.


Added Fixed label.

@sigmundch sigmundch added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. labels Mar 15, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
Projects
None yet
Development

No branches or pull requests

3 participants