[NI] Infer type variable to Nothing if all upper constraints are from upper bounds
#KT-32196 Fixed
This commit is contained in:
Generated
+5
@@ -9893,6 +9893,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt3184.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32196.kt")
|
||||
public void testKt32196() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt32196.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32415.kt")
|
||||
public void testKt32415() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt32415.kt");
|
||||
|
||||
+10
-5
@@ -18,10 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
|
||||
|
||||
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.TypeVariableDirectionCalculator.ResolveDirection
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.Constraint
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.checkConstraint
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.*
|
||||
import org.jetbrains.kotlin.types.AbstractTypeApproximator
|
||||
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
@@ -82,7 +79,15 @@ class ResultTypeResolver(
|
||||
if (!checkConstraint(this, constraint.type, constraint.kind, resultType)) return false
|
||||
}
|
||||
|
||||
if (!trivialConstraintTypeInferenceOracle.isSuitableResultedType(resultType)) return false
|
||||
/*
|
||||
* If all upper constraints came from declared upper bounds we should accept Nothing
|
||||
* as suitable type as OI does
|
||||
*/
|
||||
if (
|
||||
variableWithConstraints.constraints.any {
|
||||
it.kind == ConstraintKind.UPPER && it.position.from !is DeclaredUpperBoundConstraintPosition
|
||||
} && !trivialConstraintTypeInferenceOracle.isSuitableResultedType(resultType)
|
||||
) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <R : Any> Inv<Int>.mapNotNull(transform: (Int) -> R?): Inv<R> = null!!
|
||||
|
||||
fun test(inv: Inv<Int>) {
|
||||
inv.mapNotNull { null }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class Inv<T>
|
||||
|
||||
fun <R : Any> Inv<Int>.mapNotNull(transform: (Int) -> R?): Inv<R> = null!!
|
||||
|
||||
fun test(inv: Inv<Int>) {
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.Nothing>")!>inv.mapNotNull { null }<!>
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ inv: Inv<kotlin.Int>): kotlin.Unit
|
||||
public fun </*0*/ R : kotlin.Any> Inv<kotlin.Int>.mapNotNull(/*0*/ transform: (kotlin.Int) -> R?): Inv<R>
|
||||
|
||||
public final class Inv</*0*/ T> {
|
||||
public constructor Inv</*0*/ T>()
|
||||
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
|
||||
}
|
||||
@@ -9900,6 +9900,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt3184.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32196.kt")
|
||||
public void testKt32196() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt32196.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32415.kt")
|
||||
public void testKt32415() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt32415.kt");
|
||||
|
||||
Generated
+5
@@ -9895,6 +9895,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt3184.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32196.kt")
|
||||
public void testKt32196() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt32196.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt32415.kt")
|
||||
public void testKt32415() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/kt32415.kt");
|
||||
|
||||
Reference in New Issue
Block a user