[FIR] Fix inference in presence of Unit expected type
This commit is contained in:
committed by
TeamCityServer
parent
8624d97f29
commit
cd578e9d13
+4
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addEqualityConstraintIfCompatible
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.addSubtypeConstraintIfCompatible
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintSystemCompletionMode
|
||||
@@ -175,6 +176,9 @@ class FirCallCompleter(
|
||||
system.addSubtypeConstraint(initialType, expectedType, expectedTypeConstraintPosition)
|
||||
}
|
||||
system.notFixedTypeVariables.isEmpty() -> return
|
||||
expectedType.isUnit -> {
|
||||
system.addEqualityConstraintIfCompatible(initialType, expectedType, expectedTypeConstraintPosition)
|
||||
}
|
||||
else -> {
|
||||
system.addSubtypeConstraintIfCompatible(initialType, expectedType, expectedTypeConstraintPosition)
|
||||
}
|
||||
|
||||
compiler/testData/diagnostics/tests/inference/coercionToUnit/coercionWithExpectedTypeAndBound.fir.kt
Vendored
+2
-2
@@ -2,11 +2,11 @@
|
||||
fun <T : Number> materializeNumber(): T = TODO()
|
||||
|
||||
fun a(): Unit = run {
|
||||
<!NEW_INFERENCE_ERROR!>materializeNumber()<!>
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materializeNumber<!>()
|
||||
}
|
||||
|
||||
fun b(): Unit = run {
|
||||
run {
|
||||
<!NEW_INFERENCE_ERROR!>materializeNumber()<!>
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materializeNumber<!>()
|
||||
}
|
||||
}
|
||||
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
// !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 ->
|
||||
<!NEW_INFERENCE_ERROR!>myRun { f }<!>
|
||||
}
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
interface Base
|
||||
|
||||
Reference in New Issue
Block a user