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

case of and intersection types #11850

Merged
merged 9 commits into from
Dec 13, 2024
Merged

Conversation

JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Dec 12, 2024

Pull Request Description

Fixes #11828 by enhancing the case of nodes to recognize additional types of EnsoMultiValue.

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
  • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach added the CI: No changelog needed Do not require a changelog entry for this PR. label Dec 12, 2024
@JaroslavTulach JaroslavTulach self-assigned this Dec 12, 2024
@@ -295,7 +295,7 @@ Error.should_equal self that frames_to_skip=0 =
Number.should_equal : Float -> Float -> Integer -> Spec_Result
Number.should_equal self that epsilon=0 frames_to_skip=0 =
matches = case that of
_ : Number -> self.equals that epsilon
n : Number -> self.equals n epsilon
Copy link
Member Author

Choose a reason for hiding this comment

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

This shows a small nuance. Previously there was no difference between that and n. Now there is as 571cce6 documents.

@JaroslavTulach JaroslavTulach added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Dec 13, 2024
Copy link
Contributor

@4e6 4e6 left a comment

Choose a reason for hiding this comment

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

Please document all non-trivial logic

Copy link
Member

@Akirathan Akirathan left a comment

Choose a reason for hiding this comment

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

Looks good altogether. I have two questions though. The first one about incosistency is more important:

(1)

So type pattern branches in case of expressions don't do automatic conversions, as opposed to standard method calls.
i.e.,

a = A:A
case a of
    b: B -> "Is a B"

will not match. In other words, case expressions uncover the hidden parts of multivalue, but they don't uncover the types that the scrutinee can be cast to. I find this slightly confusing. Consider this code:

method (b:B) = b.b

main =
    a = A:A
    ax = A:A&X
    res1 = case ax of
        b: B -> b.b
        _ -> "Else"
    res2 = method ax
    [res1, res2]

res1 will be "Else", while res2 will be "b". The same thing will happen if ax is replaced with a in the case expression and method call. What is the reason for this incosistency?

(2)

Any plans to support intersection types in type patterns as well?

case ax of
    _: A&X -> ...

fails with:

/home/pavel/tmp/tmp.enso:27:12: error: Syntax is not supported yet: qualifiedNameSegment.
   27 |         _: A&X -> "Is A&X"
      |            ^~~

@JaroslavTulach
Copy link
Member Author

So type pattern branches in case of expressions don't do automatic conversions

I've asked and @radeusgd says that the pattern branches should be consistent with is_a function. E.g. no conversions.

Any plans to support intersection types in type patterns as well?

Yes, reported as #11864

@JaroslavTulach JaroslavTulach merged commit 7998ed5 into develop Dec 13, 2024
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: No changelog needed Do not require a changelog entry for this PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pattern matching a EnsoMultiValue ignores 2nd & co. types
5 participants