Skip to content
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

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Nov 20, 2024

Pull Request Description

Implementation of type checks for intersection types. The idea is to split the list of types[] in EnsoMultiValue into two parts:

  • first methodDispatchTypes represent the types the value "has been cast to"
  • the rest of the types represent the types the value "can be 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:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    TypeScript,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach self-assigned this Nov 20, 2024
@JaroslavTulach JaroslavTulach changed the title EnsoMultiValue to pass intersection type thru the -> Complex check Pass intersection type thru the -> Complex check Nov 20, 2024
@Akirathan
Copy link
Member

Idea for increasing test coverage of EnsoMultiValue: Manually create some Truffle nodes and explicitly call them. Inspiration from EqualsTest and HashCodeTest.

Copy link
Contributor

@GregoryTravis GregoryTravis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve libs change.

@JaroslavTulach
Copy link
Member Author

Idea for increasing test coverage of EnsoMultiValue: Manually create some Truffle nodes and explicitly call them. Inspiration from EqualsTest and HashCodeTest.

assertFalse("4 != t4", equalityCheck(4L, fourExtraText));
assertTrue(
"Only Text is 'dispatch type'. Not integer. Shall we be equal to 4?",
equalityCheck(4L, fourExtraText));
Copy link
Member Author

@JaroslavTulach JaroslavTulach Nov 26, 2024

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 to Text)
  • 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.

@JaroslavTulach JaroslavTulach changed the title Pass intersection type thru the -> Complex check Intersection types & type checks Nov 26, 2024
NUMBER,
POINTER,
META_OBJECT,
ITERATOR;
Copy link
Member Author

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
Copy link
Member Author

@JaroslavTulach JaroslavTulach Nov 27, 2024

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow (multi_value : Table) : Column to succeed
3 participants