NI: Fix resolution ambiguity for references returned from lambda

^KT-32267 Fixed
This commit is contained in:
Denis Zharkov
2019-12-26 17:23:14 +03:00
committed by Mikhail Zarechenskiy
parent 534718794c
commit caf02806d5
13 changed files with 290 additions and 18 deletions
@@ -0,0 +1,39 @@
// SKIP_TXT
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
fun main() {
Configuration().commands {
<!INAPPLICABLE_CANDIDATE!>Command1<!> { <!UNRESOLVED_REFERENCE!>someService<!>::execute } // Overload resolution ambiguity. All these functions match.
<!INAPPLICABLE_CANDIDATE!>Command2<!> { <!UNRESOLVED_REFERENCE!>someService<!>::execute } // Overload resolution ambiguity. All these functions match.
<!INAPPLICABLE_CANDIDATE!>Command1<!> { { <!UNRESOLVED_REFERENCE!>someService<!>.<!UNRESOLVED_REFERENCE!>execute<!>(<!UNRESOLVED_REFERENCE!>it<!>) } } // fine
<!INAPPLICABLE_CANDIDATE!>Command2<!> { { <!UNRESOLVED_REFERENCE!>someService<!>.<!UNRESOLVED_REFERENCE!>execute<!>(<!UNRESOLVED_REFERENCE!>it<!>) } } // fine
}
}
interface Command
interface CommandFactory<TCommand : Command>
class Command1 : Command {
companion object : CommandFactory<Command1>
}
class Command2 : Command {
companion object : CommandFactory<Command2>
}
class Configuration {
val commands = Commands()
inline fun commands(configure: Commands.() -> Unit) {
commands.<!UNRESOLVED_REFERENCE!>configure<!>()
}
class Commands {
operator fun <TCommand : Command> CommandFactory<TCommand>.invoke(
handler: Transaction.() -> ((command: TCommand) -> Unit)
) {
}
}
}
interface Transaction {
val someService: SomeService
}
interface SomeService {
fun execute(command: Command1)
fun execute(command: Command2)
}
@@ -0,0 +1,39 @@
// SKIP_TXT
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
fun main() {
Configuration().commands {
Command1 { someService::execute } // Overload resolution ambiguity. All these functions match.
Command2 { someService::execute } // Overload resolution ambiguity. All these functions match.
Command1 { { someService.execute(it) } } // fine
Command2 { { someService.execute(it) } } // fine
}
}
interface Command
interface CommandFactory<TCommand : Command>
class Command1 : Command {
companion object : CommandFactory<Command1>
}
class Command2 : Command {
companion object : CommandFactory<Command2>
}
class Configuration {
val commands = Commands()
inline fun commands(configure: Commands.() -> Unit) {
commands.configure()
}
class Commands {
operator fun <TCommand : Command> CommandFactory<TCommand>.invoke(
handler: Transaction.() -> ((command: TCommand) -> Unit)
) {
}
}
}
interface Transaction {
val someService: SomeService
}
interface SomeService {
fun execute(command: Command1)
fun execute(command: Command2)
}
@@ -0,0 +1,43 @@
// SKIP_TXT
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
interface Inv<T>
fun <E> Inv<E>.foo(
handler: () -> ((command: E) -> Unit)
) {}
fun bar(x: Int) {}
fun bar(x: String) {}
fun bar1(arg: Int) {}
fun foo1(f: () -> (Int) -> Unit) = ""
fun main(x: Inv<Int>) {
x.foo<Int> {
if (x.hashCode() == 0) return@foo <!UNRESOLVED_REFERENCE!>::bar<!>
::bar
}
x.foo {
if (x.hashCode() == 0) return@foo <!UNRESOLVED_REFERENCE!>::bar<!>
::bar
}
foo1 {
::bar1
}
foo1 {
return@foo1 ::bar1
}
foo1 {
if (x.hashCode() == 0) return@foo1 <!UNRESOLVED_REFERENCE!>::bar<!>
::bar
}
}
@@ -0,0 +1,43 @@
// SKIP_TXT
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +NewInference
interface Inv<T>
fun <E> Inv<E>.foo(
handler: () -> ((command: E) -> Unit)
) {}
fun bar(x: Int) {}
fun bar(x: String) {}
fun bar1(arg: Int) {}
fun foo1(f: () -> (Int) -> Unit) = ""
fun main(x: Inv<Int>) {
x.foo<Int> {
if (x.hashCode() == 0) return@foo ::bar
::bar
}
x.foo {
if (x.hashCode() == 0) return@foo ::bar
::bar
}
foo1 {
::bar1
}
foo1 {
return@foo1 ::bar1
}
foo1 {
if (x.hashCode() == 0) return@foo1 ::bar
::bar
}
}