-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4364: Try SAM type when no candidates found #4821
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
Changes from all commits
0ef2206
770e49f
b4d8776
5685a99
653b2e4
f5758a5
ac97d90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
object Test { | ||
def foo(c: java.util.function.Consumer[Integer]) = c.accept(0) | ||
def f(x: Int): Unit = () | ||
|
||
def main(args: Array[String]) = { | ||
foo(f) // Ok: Consumer is @FunctionalInterface | ||
new java.io.ObjectOutputStream(f) // error: OutputStream is not @FunctionalInterface | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import java.util.function.Consumer | ||
|
||
object Test { | ||
def f(): Unit = assert(false) | ||
def f(x: Int): Unit = assert(false) | ||
def f(x: String): Unit = () | ||
|
||
def foo(c: Consumer[String]) = c.accept("") | ||
|
||
def main(args: Array[String]) = { | ||
foo(f) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import java.util.function.Consumer | ||
|
||
object Test { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is not clear what you are testing here that is not tested in class Test {
def foo(c: java.util.function.Consumer[String]) = ()
def bar(out: java.io.OutputStream) = ()
bar(x => println(x))
bar(println(_))
bar(println) // error: OutputStream is not @FunctionalInterface
def f(x: String) = ()
foo(f) // Ok: Consumer is @FunctionalInterface
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. def f(x: Int): Unit = assert(false)
def f(x: String): Unit = assert(false)
def f: java.io.OutputStream = new java.io.OutputStream { def write(x: Int) = () }
val oosF = new java.io.ObjectOutputStream(f)
oosF.write(0) Through the test, I tried to check that whether method overloading is correctly resolved when candidates exist without considering SAM type. In this case, the second As you suggested, it would be better to check a warning in a seperate test. I'll remove val oosG = new java.io.ObjectOutputStream(g)
oosG.write(0)
oosG.close() from test b and add a test about a warning in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I suggest a simpler test though: import java.util.function.Consumer
object Test {
def foo(c: Consumer[String]) = c.accept("")
def bar(x: String): Unit = ???
def bar: Consumer[String] = new Consumer { def accept(s: String) = () }
def main(args: Array[String]) = {
foo(bar)
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this one is simpler and clearer. I'll fix it. Thank you! |
||
def f(x: String): Unit = assert(false) | ||
def f: Consumer[String] = new Consumer { def accept(s: String) = () } | ||
|
||
def foo(c: Consumer[String]) = c.accept("") | ||
|
||
def main(args: Array[String]) = { | ||
foo(f) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpick: I'd change the condition to