Skip to content

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 23, 2024

When comparing arguments of two applied types, perform hard comparisons after easy ones. A comparison is hard if it entails a subtype test A <: B where A is an AndType or B is an OrType. Such comparisons need to perform an either, which might lose solutions.

Fixes #19999

When comparing arguments of two applied types, perform hard comparisons
after easy ones. A comparison if hard if it entails a subtype test A <: B
where A is an AndType or B is an OrType. Such comparisons need to perform an either,
which might lose solutions.

Fixes scala#19999
@odersky
Copy link
Contributor Author

odersky commented Mar 23, 2024

We could possibly generalize this, delaying hard comparisons in more conjunctive tests, not just type in arguments. But it is hard in general to identify a conjunctive subsequence of tests when doing a subtype traversal.

@odersky odersky requested a review from smarter March 23, 2024 15:01
@dwijnand
Copy link
Member

Interesting! I've had a case that required this defer too.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.

* So we defer such tests to run last, on the chance that some other argument
* comparison will instantiate or constrain type variables first.
*/
def isHard(arg1: Type, arg2: Type): Boolean =
Copy link
Member

Choose a reason for hiding this comment

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

Using the word hard here might lead to confuse with hard unions since OrTypes are also involved. Maybe we could call this isIncomplete instead?

@smarter smarter assigned odersky and unassigned smarter Mar 25, 2024
Co-authored-by: Guillaume Martres <smarter@ubuntu.com>
@smarter smarter merged commit 5c6524a into scala:main Mar 26, 2024
@smarter smarter deleted the fix-19999 branch March 26, 2024 14:43
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
WojciechMazur added a commit that referenced this pull request Jul 5, 2024
Backports #20007 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

No longer able to extract a type from an intersection
4 participants