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

[Backport] Overloading resolution: Handle SAM types more like Java and Scala 2 #12131

Merged
merged 3 commits into from
Apr 17, 2021

Commits on Apr 17, 2021

  1. SAM types cannot be sealed or final

    Previously we caught this in Typer, but doing it in the `SAMType`
    extractor is more robust because it is used in overloading resolution,
    and this will be needed in a subsequent commit of this PR to avoid
    selecting the wrong overload in some cases.
    
    This required dropping the final flag from the compiler-generated
    ContextFunctionN, instead we explicitly prevent subclasses in RefChecks.
    smarter committed Apr 17, 2021
    Configuration menu
    Copy the full SHA
    675d44f View commit details
    Browse the repository at this point in the history
  2. Drop first pass in narrowByTrees

    The two pass approach was originally introduced in
    295c981 to lower the priority of
    implicit conversions, but just a month later in
    6253125 a similar two pass approach was
    used to call resolveOverloaded which itself calls narrowByTrees,
    rendering the first commit moot.
    
    Therefore, we can just remove this first pass and all associated code
    without affecting anything.
    smarter committed Apr 17, 2021
    Configuration menu
    Copy the full SHA
    ccfbf15 View commit details
    Browse the repository at this point in the history
  3. Overloading resolution: Handle SAM types more like Java and Scala 2

    `resolveOverloaded` is called twice, first with implicit conversions
    off, then on. Before this commit, turning off implicit conversions also
    turned off SAM conversions, this behavior does not match Java or Scala 2
    which means we could end up picking a different overload than they
    do (cf scala#11938).
    
    This commit enables SAM conversions in the first pass, _except_ for
    conversions to PartialFunction as that would break a lot of existing
    code and wouldn't match how either Java or Scala 2 pick overloads.
    
    This is an alternative to scala#11945 (which special-cased
    SAM types with an explicit `@FunctionalInterfaces` annotation) and scala#11990
    (which special-cased SAM types that subtype a scala Function type).
    Special-casing PartialFunction instead seems more defensible since it's
    already special-cased in Scala 2 and is not considered a SAM type by
    Java.
    
    Fixes scala#11938.
    smarter committed Apr 17, 2021
    Configuration menu
    Copy the full SHA
    990a01f View commit details
    Browse the repository at this point in the history