You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
/// A [Comparator] that uses a [FastFieldAccessor] to speed up comparisons based/// on nested fields in an [Entity].classFastComparator<SextendsEntity, T> {
finalFastFieldAccessor<S, T> accessor;
finalComparator<T> comparator;
FastComparator(String field) :this.withComparator(field,
*/* DDC:severe: StaticTypeError, Type check failed: Comparable.compare ((Comparable<dynamic>, Comparable<dynamic>) → int) is not of type (T, T) → int */Comparable.compare);
FastComparator.withComparator(String field, this.comparator) :
accessor =newFastFieldAccessor<S, T>(field);
intcall(S a, S b) =>comparator(accessor[a], accessor[b]);
}
The text was updated successfully, but these errors were encountered:
Why is this spurious? The comparator field has type T * T -> int, which is completely unrelated to the type of Comparable.compare (i.e. Comparable * Comparable -> int). Nothing stops me from instantiating this class with a T which does not satisfy the Comparable interface, right? I think declaring this as T extends Comparable might solve the issue here, since we need Comparable * Comparable -> int <: T * T -> int, i.e. T <: Comparable, which is what T extends Comparable should give you.
Good point. Unfortunately, I can't set T extends Comparator due to the other constructor.
We could make this constructor assert
T is Comparable which is really the user's intent.
For now I've added the following todo to the code
// TODO(jacobr): we would like to use Comparable.compare but that method
// requires that T be a Comparator which we do not want to enforce for
// all FastComparator objects, only ones that use this constructor.
The text was updated successfully, but these errors were encountered: