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

Under -Xsource:3, don't auto-eta-expand nilary methods to SAM types #9049

Merged
merged 1 commit into from Jun 11, 2020

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Jun 10, 2020

A piece of code such as:

class C(s: java.io.InputStream)
class D(u: java.net.URL) extends C(u.openStream)

could be interpreted in two ways.

  1. InputStream is a SAM of def read(): Int, and C(u.openStream) requires an eta-expansion from openStream method to () => Int.
  2. u.openStream needs auto application ().

Under -Xsource:3 Scala 2.13.2 took the first interpretation, since #7660, and then errored with surprising:

       error: type mismatch;
        found   : java.io.InputStream
        required: Int

This PR fixes that by not eta-expanding nilary methods when a SAM type is expected.

Fixes scala/bug#12006; supersedes #9027

@scala-jenkins scala-jenkins added this to the 2.13.4 milestone Jun 10, 2020
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Jun 11, 2020
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

very nice cleanup

@lrytz lrytz modified the milestones: 2.13.4, 2.13.3 Jun 11, 2020
@lrytz lrytz merged commit 0ff65a0 into scala:2.13.x Jun 11, 2020
@dwijnand dwijnand deleted the no-eta-sam-3 branch June 11, 2020 14:17
@SethTisue SethTisue changed the title Remove eta-expansion of SAM under -Xsource:3 Remove eta-expansion of SAMs under -Xsource:3 Jun 23, 2020
@SethTisue SethTisue changed the title Remove eta-expansion of SAMs under -Xsource:3 Under -Xsource:3, disallow eta-expansion of SAMs Jun 23, 2020
@SethTisue SethTisue changed the title Under -Xsource:3, disallow eta-expansion of SAMs Under -Xsource:3, don't eta-expand nilary methods to SAM types Jun 23, 2020
@SethTisue
Copy link
Member

@dwijnand I brought over Eugene's description from #9027; can you see if it needs any further adjustment/clarification?

@SethTisue SethTisue changed the title Under -Xsource:3, don't eta-expand nilary methods to SAM types Under -Xsource:3, don't auto-eta-expand nilary methods to SAM types Jun 23, 2020
@dwijnand
Copy link
Member Author

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
4 participants