[NI] Fix inference of lambda with receiver when wrapped...

in when/if or another lambda.
#KT-37419 fixed
This commit is contained in:
Ilya Chernikov
2020-04-12 18:20:31 +02:00
parent 6494a2d902
commit acc5633811
10 changed files with 228 additions and 23 deletions
@@ -0,0 +1,45 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
interface Receiver
interface Parameter
typealias LambdaWithReceiver = Receiver.(Parameter) -> Unit
fun Receiver.method(param: Parameter): LambdaWithReceiver = TODO()
enum class E { VALUE }
fun <K> id(x: K): K = x
class SomeClass {
val e = E.VALUE
val withoutType: LambdaWithReceiver
get() = when (e) {
E.VALUE -> { param ->
<!INAPPLICABLE_CANDIDATE!>method<!>(param)
}
}
val withExplicitType: LambdaWithReceiver
get() = when (e) {
E.VALUE -> { param: Parameter ->
<!INAPPLICABLE_CANDIDATE!>method<!>(param)
}
}
}
class OtherClass {
val ok: LambdaWithReceiver
get() = { param: Parameter ->
method(param)
}
}
val e2 = E.VALUE
val staticWithExplicitType: LambdaWithReceiver
get() = when (e2) {
E.VALUE -> { param: Parameter ->
<!UNRESOLVED_REFERENCE!>method<!>(param)
}
}
@@ -0,0 +1,45 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
interface Receiver
interface Parameter
typealias LambdaWithReceiver = Receiver.(Parameter) -> Unit
fun Receiver.method(param: Parameter): LambdaWithReceiver = TODO()
enum class E { VALUE }
fun <K> id(x: K): K = x
class SomeClass {
val e = E.VALUE
val withoutType: LambdaWithReceiver
get() = when (e) {
E.VALUE -> { param ->
method(param)
}
}
val withExplicitType: LambdaWithReceiver
get() = when (e) {
E.VALUE -> { param: Parameter ->
method(param)
}
}
}
class OtherClass {
val ok: LambdaWithReceiver
get() = { param: Parameter ->
method(param)
}
}
val e2 = E.VALUE
val staticWithExplicitType: LambdaWithReceiver
get() = when (e2) {
E.VALUE -> { param: Parameter ->
method(param)
}
}
@@ -0,0 +1,56 @@
package
public val e2: E
public val staticWithExplicitType: LambdaWithReceiver /* = Receiver.(Parameter) -> kotlin.Unit */
public fun </*0*/ K> id(/*0*/ x: K): K
public fun Receiver.method(/*0*/ param: Parameter): LambdaWithReceiver /* = Receiver.(Parameter) -> kotlin.Unit */
public final enum class E : kotlin.Enum<E> {
enum entry VALUE
private constructor E()
public final override /*1*/ /*fake_override*/ val name: kotlin.String
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: E): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<E!>!
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): E
public final /*synthesized*/ fun values(): kotlin.Array<E>
}
public final class OtherClass {
public constructor OtherClass()
public final val ok: LambdaWithReceiver /* = Receiver.(Parameter) -> kotlin.Unit */
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Parameter {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface Receiver {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class SomeClass {
public constructor SomeClass()
public final val e: E
public final val withExplicitType: LambdaWithReceiver /* = Receiver.(Parameter) -> kotlin.Unit */
public final val withoutType: LambdaWithReceiver /* = Receiver.(Parameter) -> kotlin.Unit */
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public typealias LambdaWithReceiver = Receiver.(Parameter) -> kotlin.Unit