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

Fix #4364: Try SAM type when no candidates are found #5717

Merged
merged 8 commits into from Jan 16, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 15, 2019

For overloading resolution, try a SAM type when no candidates are found.

Also, issue a warning when eta-expanding to a SAM type without a @FunctionalInterface
annotation.

Based on #4821

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

Copy link
Contributor

@adriaanm adriaanm left a comment

Choose a reason for hiding this comment

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

LGTM, with a question to confirm my understanding

@@ -3,7 +3,7 @@ import collection._
object Test {
def check(obj: AnyRef): Unit = {
val bos = new ByteArrayOutputStream()
val out = new ObjectOutputStream(println) // error
val out = new ObjectOutputStream(println)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the overload is now resolved, but it's still a warning (OutputStream is not @FunctionalInterface), right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you get:

6 |    val out = new ObjectOutputStream(println)
  |                                     ^^^^^^^
  |method println is eta-expanded even though java.io.OutputStream does not have the @FunctionalInterface annotation.

@odersky odersky merged commit c1b8bd0 into scala:master Jan 16, 2019
@Blaisorblade Blaisorblade deleted the fix-issue4364 branch January 16, 2019 15:02
@adriaanm
Copy link
Contributor

adriaanm commented Jan 16, 2019

Oh, one more semi-related question to eta-expansion of 0-argument methods. Is #2570 (comment) still the intended spec?

Especially this part:

  1. if m is nullary (i.e. has type ()R):
    i. If the expected type is of the form () => T, we eta expand.

does not seem to be implemented:

https://github.com/lampepfl/dotty/blob/4ecbb60119008febec99c153025ecd03da428c12/compiler/src/dotty/tools/dotc/typer/Typer.scala#L2491-L2504

We're discussing this over in scala/scala#6475.

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.

None yet

4 participants