-
Notifications
You must be signed in to change notification settings - Fork 323
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
Enforce conversion method return type & redefine Comparable #10468
Enforce conversion method return type & redefine Comparable #10468
Conversation
Can we still return errors from |
Yes. |
At 33 failing tests with 18dde9b as this report confirms. Time to execute some benchmarks: |
The problem for today is that following program works: from Standard.Base import Vector, Comparable
type T
Value a b
type T_Comparator
compare t1 t2 = Comparable.from t1.a . compare t2.a
hash t = Comparable.from t.a . hash
Comparable.from (that:T) = Comparable.new that T_Comparator
main = [T.Value 1 2, T.Value 1 2] . distinct but when one changes the first line to from Standard.Base import all then it doesn't and yields:
Update: workarounded by a639364 |
There is only a single remaining failure:
how do I run the PostgreSQL tests? Usage of
I can see the failure locally. |
This failure has nothing to do with
when comparing polyglot java import java.math.BigInteger
from Standard.Base import all
import Standard.Base.Internal.Ordering_Helpers.Default_Comparator
main =
f = BigInteger.new "5"
t = BigInteger.new "13"
r = Default_Comparator.compare_callback f t
[ r ] Solved by a2c4def |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is still not entirely clear to me why a custom comparator's compare
method can throw Incomparable_Values
. But I don't see any big problems with that. Looks good overall to me.
distribution/lib/Standard/Base/0.0.0-dev/src/Data/Ordering.enso
Outdated
Show resolved
Hide resolved
Co-authored-by: Pavel Marek <[email protected]>
There are many places where comparator's
Yes, relaxing the rules costs us nothing and the delegation is then very simple. |
Pull Request Description
Fixes #10355 by enforcing return type of
Xyz.from
conversion methods. Most frequent violations are caused by ordering support - hence 280b7a7 definesComparable.new
to address the problem:Ordering.compare
to compare two values to be equal, less or greater or uncomparableOrdering.hash
to compute hash code for any object in EnsoComparable.new
while implementingComparable.from
conversion to controlcompare
andhash
for an objectThose are the most important API changes. Other types, like
Default_Comparator
were moved outside of the API intoprivate
module.Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
style guides.