Skip to content

Fix #15405: Dealias Or type constituents when finding its dominator #15416

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

Merged
merged 1 commit into from
Jun 15, 2022

Conversation

anatoliykmetyuk
Copy link
Contributor

@anatoliykmetyuk anatoliykmetyuk commented Jun 10, 2022

In the issue, v: Int is boxed to RichInt. This is because the typer can't find > in Int | Validated[Int] and attempts an implicit conversion. This is in turn because when looking up members of a union type, we do the join operation on that union type, which attempts to simplify it by reducing it to the intersection of the base classes of its constituents.

It seems that this intersection algorithm, while operating on dealiased constituents, does not dealias them at a certain point, thus judging that the intersection of base types of Int and Validated[Int] is Any. This PR adds such a dealias.

Using Foo instead of Int in tests to remove implicit conversions out of the equation; without the PR's change the test fails.

@anatoliykmetyuk anatoliykmetyuk self-assigned this Jun 10, 2022
@anatoliykmetyuk anatoliykmetyuk linked an issue Jun 10, 2022 that may be closed by this pull request
@anatoliykmetyuk anatoliykmetyuk requested a review from odersky June 10, 2022 16:05
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Normally, baseClasses should already do dealiasing, but it seems in the case of AppliedType they did not. Can you try the following change to baseClasses in Types.scala, line 597?

Change

            tp.underlying.baseClasses

to

            tp.superType.baseClasses

If that works I would think it's a better fix than the change in TypeOps.

@odersky odersky assigned anatoliykmetyuk and unassigned odersky Jun 10, 2022
@odersky
Copy link
Contributor

odersky commented Jun 14, 2022

@anatoliykmetyuk Any progress on this?

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Nice that this worked!

@odersky odersky merged commit ad1939a into scala:main Jun 15, 2022
@odersky odersky deleted the fix-15405 branch June 15, 2022 07:30
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
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.

Unnecessary boxing when calling > on complex int type
3 participants