Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Nov 20, 2025

Ignore selection prototypes at first when typing type applications. If we need them later for overloading disambiguation, reveal the ignored type.

The reason for doing this is that a selection might come from an extension method, and in this case we should not require the selected name as a member of the result.

This change breaks one test (overloading-specifity-2.scala) that explicitly tested that we don't consult implicit arguments for disambiguation since the expected type was a selection that already determined the outcome. This logic no longer holds. We have to see whether this change breaks any code in practice.

Fixes #23773

@odersky odersky requested a review from hamzaremmal November 20, 2025 12:17
@odersky
Copy link
Contributor Author

odersky commented Nov 20, 2025

@hamzaremmal I am surprised to not see community build tasks in the task list. Where are they?

@hamzaremmal
Copy link
Member

They are there, they just kick in later.

@hamzaremmal
Copy link
Member

@WojciechMazur can we have an Open CB run on this PR? Thanks.

@hamzaremmal hamzaremmal added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Nov 20, 2025
@WojciechMazur
Copy link
Contributor

Sure, I'll schedule the build as soon as I'll fix some infra problems

@odersky
Copy link
Contributor Author

odersky commented Nov 20, 2025

This should be backported to 3.8.0 if it works but not to 3.3 since it involves a change in behavior.

@hamzaremmal
Copy link
Member

hamzaremmal commented Nov 20, 2025

This should be backported to 3.8.0 if it works but not to 3.3 since it involves a change in behavior.

Yes, the label is for 3.8.0, not 3.3.x

Copy link
Member

@hamzaremmal hamzaremmal left a comment

Choose a reason for hiding this comment

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

LGTM but I'll wait for the Open CB run result before approving.

@WojciechMazur
Copy link
Contributor

WojciechMazur commented Nov 22, 2025

Sorry for long delay but we had problems with OpenCB infra.
I've found 3 project that seems to be affected by this PR resulting in fail, but which do compile in latest nightly.

Here's the first reproduced issue from eikek/soidc

trait NumericDate
trait JWSDecoded[H]

trait StandardHeaderWrite[H]:
  def setAlgorithm(header: H, algorithm: Algorithm): H

object StandardHeaderWrite:
  def apply[H](using sh: StandardHeaderWrite[H]): StandardHeaderWrite[H] = ???
  // unused - required to reproduce
  def apply[H](setAlg: (H, Algorithm) => H): StandardHeaderWrite[H] = ???

final case class JWK(algorithm: Option[Algorithm])
sealed trait Algorithm

def Test[F[_], H](key: JWK, header: H)(using StandardHeaderWrite[H]) = {
  key.algorithm
    .map(StandardHeaderWrite[H].setAlgorithm(header, _))
    .getOrElse(header)
}
ompiling project (Scala 3.8.1-RC1-bin-20251120-60444cb, JVM (21))
[error] ./test.scala:17:10
[error] value setAlgorithm is not a member of ((H, Algorithm) => H) => StandardHeaderWrite[H]
[error]     .map(StandardHeaderWrite[H].setAlgorithm(header, _))
[error]          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2 additional failed projects without reproduction, however these seem similar to existing issues fixed in current main

Project Version Build URL Notes
kacperfkorban/guinep 0.1.1 Open CB logs Similar to #23969 passed in main
paoloboni/binance-scala-client 1.6.1 Open CB logs Probably the same as #24093 passes latest nightly

@odersky
Copy link
Contributor Author

odersky commented Nov 22, 2025

Thanks for the minimization! That looks like expected behavior after the change in this PR. In StandardHeaderWrite[H].setAlgorithm we are choosing the alternative without knowledge of the expected result type now. That would resolve to the second apply, since that second apply does not require an implicit parameter. But the chosen alternative does not match the selection prototype once it is revealed.

I can see one possible improvement of the PR: We could maybe retain the fact somehow that we expect some selection, to rule out the alternative where the next action would be an application. Let me try that.

Ignore selection prototypes at first when typing type applications.
If we need them later for overloading disambiguation, reveal the ignored
type.

The reason for doing this is that a selection might come from an extension method,
and in this case we should not require the selected name as a member of the result.

This change breaks one test (overloading-specifity-2.scala) that explicitly
tested that we don't consult implicit arguments for disambiguation since the
expected type was a selection that already determined the outcome. This is logic
no longer holds. We have to see whether this change breaks any code in practice.

Fixes scala#23773
Fixes the Open CB counter example.
@odersky
Copy link
Contributor Author

odersky commented Nov 23, 2025

I managed to make the minimizer compiler with some additional tweaks.

@odersky odersky merged commit d5fec8f into scala:main Nov 24, 2025
45 checks passed
@odersky odersky deleted the fix-23773 branch November 24, 2025 09:01
@WojciechMazur WojciechMazur added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels Nov 24, 2025
WojciechMazur added a commit that referenced this pull request Nov 25, 2025
…to 3.8.0 (#24532)

Backports #24489 to the 3.8.0-RC2.

PR submitted by the release tooling.
[skip ci]
@WojciechMazur WojciechMazur added backport:done This PR was successfully backported. and removed backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" labels Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:done This PR was successfully backported.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overload resolution fails to disambiguate between the alternatives

3 participants