-
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
Intersection types & type checks #11600
base: develop
Are you sure you want to change the base?
Conversation
-> Complex
check-> Complex
check
Idea for increasing test coverage of |
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.
Approve libs change.
|
afc04b2
to
c780c37
Compare
…or EnsoMultiValue
assertFalse("4 != t4", equalityCheck(4L, fourExtraText)); | ||
assertTrue( | ||
"Only Text is 'dispatch type'. Not integer. Shall we be equal to 4?", | ||
equalityCheck(4L, fourExtraText)); |
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.
Open question: what's the desired behavior in this (x : Text & Integer) : Text
case?
assertFalse("4 != t4", equalityCheck(4L, fourExtraText));
assertTrue("4 == t4",equalityCheck(4L, fourExtraText));
Does the final object can still be equal - e.g. represent Integer
(without being casted to it) - or it can only be equal to Text
?
Resolution: Since be5dbe8 the obj : Text
cannot be equal to Integer
. The extra Integer
type is shadowed:
- one would have to cast the object again
(obj : Text) : Integer
to be equal to integer (but then it would be no longer equal toText
) - one would have to cast the object to both
(obj : Text) : (Integer & Text)
to be equal to both integer and the text
This way we respect the ascribed type of a value while allowing it to be cast to the extra types and get extra behavior.
-> Complex
checkNUMBER, | ||
POINTER, | ||
META_OBJECT, | ||
ITERATOR; |
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.
Turns out that these types are mutually exclusive:
The following type combinations are mutually exclusive and cannot return true for the type check message of the same receiver value:
Null
Boolean
String
Number
Date, Time or TimeZone
Duration
Exception
Meta-Object
Iterator
as such the following find
method always selects at most one of the above types and that is the interop type of the multi value.
ax = A:A&X | ||
x = ax : X | ||
# should it fail? X cannot be converted to B, but there is "extra" | ||
# A in the x and allows the to_b_to_c conversion to succeed |
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.
If we want the call to to_b_to_c x
to fail, then we need to restrict the from
conversions of EnsoMultiValue
only to the methodDispatchTypes
...
Pull Request Description
Implementation of type checks for intersection types. The idea is to split the list of
types[]
inEnsoMultiValue
into two parts:methodDispatchTypes
represent the types the value "has been cast to"By performing this separation we address the #10882 requirements. After a type check only methods available on the
methodDispatchTypes
can be invoked. However the value can still be cast to all the possible types.Important Notes
@Akirathan, @radeusgd please check the idea, feel free to contribute new test cases. The goal of this PR is to get the dispatch/cast logic right. The next step would be to make it fast.
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
TypeScript,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.