diff --git a/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt index d4609ff4ed4..93be2ea5826 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/checkNothingIsSubtype.kt @@ -6,7 +6,7 @@ interface A fun infer(a: A) : T {} fun test(nothing: Nothing?) { - val i = infer(nothing) + val i = infer(nothing) } fun sum(a : IntArray) : Int { diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt index 3ddce693ea7..0dcb454384e 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt1127.kt @@ -5,5 +5,5 @@ package d fun asList(t: T) : List? {} fun main(args : Array) { - val list : List = asList("") + val list : List = asList("") } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt index 00812285eeb..dcdb09ce8b9 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2286.kt @@ -11,14 +11,14 @@ abstract class Buggy { } val anotherThree : Int - get() = coll.find{ it > 3 } // does not work here + get() = coll.find{ it > 3 } // does not work here val yetAnotherThree : Int - get() = coll.find({ v:Int -> v > 3 }) // neither here + get() = coll.find({ v:Int -> v > 3 }) // neither here val extendedGetter : Int get() { - return coll.find{ it > 3 } // not even here! + return coll.find{ it > 3 } // not even here! } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2838.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2838.kt index 88f60df8089..f16eaffd65f 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2838.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2838.kt @@ -7,7 +7,7 @@ fun bar(a: T, b: Map) = b.get(a) fun test(a: Int) { foo(a, null) - bar(a, null) + bar(a, null) } fun test1(a: Int) { foo(a, throw Exception()) diff --git a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.kt b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.kt index a600e821cfc..56ec2680c6c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/inference/annotationsForResolve/noInferAnnotation.kt @@ -21,7 +21,7 @@ fun List.contains1(e: @kotlin.internal.NoInfer T): Boolean = true fun test(i: Int?, a: Any, l: List) { l.contains1(a) l.contains1("") - l.contains1(i) + l.contains1(i) } @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt index 5a5de396eea..a5a19934a6e 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/calls/inference/ConstraintSystemImpl.kt @@ -41,6 +41,7 @@ import org.jetbrains.kotlin.types.checker.TypeCheckingProcedureCallbacks import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.types.typeUtil.getNestedArguments import org.jetbrains.kotlin.types.typeUtil.isDefaultBound +import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import java.util.* public class ConstraintSystemImpl : ConstraintSystem { @@ -474,15 +475,19 @@ public class ConstraintSystemImpl : ConstraintSystem { } private fun satisfyInitialConstraints(): Boolean { - fun JetType.substituteAndMakeNullable(): JetType? { + fun JetType.substitute(): JetType? { val substitutor = getSubstitutor(substituteOriginal = false) { TypeProjectionImpl(ErrorUtils.createUninferredParameterType(it)) } - val result = substitutor.substitute(this, Variance.INVARIANT) ?: return null - return TypeUtils.makeNullable(result) + return substitutor.substitute(this, Variance.INVARIANT) ?: return null } return initialConstraints.all { - val resultSubType = it.subtype.substituteAndMakeNullable() ?: return false - val resultSuperType = it.superType.substituteAndMakeNullable() ?: return false - when (it.kind) { + constraint -> + val resultSubType = constraint.subtype.substitute()?.let { + // the call might be done via safe access, so we check for notNullable receiver type; + // 'unsafe call' error is reported otherwise later + if (constraint.position.kind != ConstraintPositionKind.RECEIVER_POSITION) it else it.makeNotNullable() + } ?: return false + val resultSuperType = constraint.superType.substitute() ?: return false + when (constraint.kind) { SUB_TYPE -> JetTypeChecker.DEFAULT.isSubtypeOf(resultSubType, resultSuperType) EQUAL -> JetTypeChecker.DEFAULT.equalTypes(resultSubType, resultSuperType) }