Fix coercion to Unit when variable already have other constraints
Don't add `Unit` if variable has an upper constraint T <: A. It's impossible to coerce variable T to Unit as constraint system will be always contradictory: T := Unit => Unit should be subtype of A #KT-39900 Fixed
This commit is contained in:
Vendored
+2
-2
@@ -3,11 +3,11 @@
|
||||
fun <T : Number> materializeNumber(): T = TODO()
|
||||
|
||||
fun a(): Unit = run {
|
||||
<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materializeNumber<!>()
|
||||
<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materializeNumber<!>()
|
||||
}
|
||||
|
||||
fun b(): Unit = run {
|
||||
run {
|
||||
<!OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materializeNumber<!>()
|
||||
<!NI;NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, OI;TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materializeNumber<!>()
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Base
|
||||
class Foo : Base
|
||||
|
||||
fun <T : Base> myRun(action: () -> T): T = action()
|
||||
|
||||
fun foo(f: (Foo) -> Unit) {}
|
||||
|
||||
fun main() {
|
||||
foo { f: Foo ->
|
||||
myRun { f }
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ f: (Foo) -> kotlin.Unit): kotlin.Unit
|
||||
public fun main(): kotlin.Unit
|
||||
public fun </*0*/ T : Base> myRun(/*0*/ action: () -> T): T
|
||||
|
||||
public interface Base {
|
||||
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 Foo : Base {
|
||||
public constructor Foo()
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user