diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt index 82fd5307d41..682c676f722 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/InferenceUtil.kt @@ -54,7 +54,7 @@ class InferenceComponents( val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx) private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle) private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default) - val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle, null) + val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle) fun createConstraintSystem(): NewConstraintSystemImpl { return NewConstraintSystemImpl(injector, ctx) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt index cfc4e76e550..3547bece1c8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/IntegerLiteralTypeApproximationTransformer.kt @@ -90,8 +90,8 @@ class IntegerLiteralTypeApproximationTransformer( val expectedType: ConeKotlinType? = when { !leftIsIlt && !rightIsIlt -> return operatorCall.compose() leftIsIlt && rightIsIlt -> null - leftIsIlt -> rightArgument.typeRef.coneTypeUnsafe() - rightIsIlt -> leftArgument.typeRef.coneTypeUnsafe() + leftIsIlt -> rightArgument.typeRef.coneTypeUnsafe() + rightIsIlt -> leftArgument.typeRef.coneTypeUnsafe() else -> throw IllegalStateException() } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 49267b47292..c980d7c0f11 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -17953,6 +17953,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.kt"); } + @TestMetadata("testNestedSpecialCalls.kt") + public void testTestNestedSpecialCalls() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.kt"); + } + @TestMetadata("TypeMismatchOnUnaryOperations.kt") public void testTypeMismatchOnUnaryOperations() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt index 532ab51b610..4f97e885b86 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinResolutionStatelessCallbacksImpl.kt @@ -97,12 +97,4 @@ class KotlinResolutionStatelessCallbacksImpl( else ConstraintSystemBuilderImpl.forSpecificity() } - - override fun isSpecialFunctionTypeParameterName(name: Name): Boolean { - return ControlStructureTypingUtils.ResolveConstruct.values().any { it.specialTypeParameterName == name } - } - - override fun isExclExclTypeParameterName(name: Name): Boolean { - return name == ControlStructureTypingUtils.ResolveConstruct.EXCL_EXCL.specialTypeParameterName - } } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt index 5ec9f8ba7d9..c2bfecd723e 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ExternalComponents.kt @@ -40,10 +40,6 @@ interface KotlinResolutionStatelessCallbacks { fun createConstraintSystemForOverloadResolution( constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns ): SimpleConstraintSystem - - fun isSpecialFunctionTypeParameterName(name: Name): Boolean - - fun isExclExclTypeParameterName(name: Name): Boolean } // This components hold state (trace). Work with this carefully. diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt index 505b18018d0..8732f958034 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ResultTypeResolver.kt @@ -30,8 +30,7 @@ import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext class ResultTypeResolver( val typeApproximator: AbstractTypeApproximator, - val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle, - private val statelessCallbacks: KotlinResolutionStatelessCallbacks? // TODO injection in FIR + val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle ) { interface Context : TypeSystemInferenceExtensionContext { fun isProperType(type: KotlinTypeMarker): Boolean @@ -85,20 +84,12 @@ class ResultTypeResolver( if (!checkConstraint(this, constraint.type, constraint.kind, resultType)) return false } if (!trivialConstraintTypeInferenceOracle.isSuitableResultedType(resultType)) { - if (nothingIsForbiddenFor(variableWithConstraints.typeVariable)) return false if (resultType.isNullableType() && checkSingleLowerNullabilityConstraint(filteredConstraints)) return false } return true } - private fun nothingIsForbiddenFor(variable: TypeVariableMarker): Boolean { - val parameterName = variable.safeAs()?.originalTypeParameter?.name ?: return false - val isSpecialFunctionParameter = statelessCallbacks?.isSpecialFunctionTypeParameterName(parameterName) ?: false - val isFromExclExcl = isSpecialFunctionParameter && statelessCallbacks?.isExclExclTypeParameterName(parameterName) ?: false - return isSpecialFunctionParameter && !isFromExclExcl - } - private fun checkSingleLowerNullabilityConstraint(constraints: List): Boolean { return constraints.singleOrNull { it.kind.isLower() }?.isNullabilityConstraint ?: false } diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.kt index 83a43ec4c73..c206beef9b1 100644 --- a/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.kt +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/elvisNotProcessed.kt @@ -15,7 +15,7 @@ val ww = if (true) { { true } ?: null!! } else if (true) { - { true } ?: null!! + { true } ?: null!! } else { null!! diff --git a/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt index adbdda52fea..32a5a618f77 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt32836.fir.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE inline fun parse(json: String): T? = TODO() diff --git a/compiler/testData/diagnostics/tests/regressions/kt32836.kt b/compiler/testData/diagnostics/tests/regressions/kt32836.kt index adbdda52fea..67d09adb679 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt32836.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt32836.kt @@ -1,4 +1,5 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE inline fun parse(json: String): T? = TODO() @@ -6,7 +7,7 @@ class MyType fun parseMyData(json: String): MyType = try { - parse(json) // error with new inf only: Cannot use 'Nothing?' as reified type parameter + parse(json) // error with new inf only: Cannot use 'Nothing?' as reified type parameter ?: throw IllegalArgumentException("Can't parse") } catch (e: Exception) { throw IllegalArgumentException("Can't parse") diff --git a/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.fir.kt b/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.fir.kt new file mode 100644 index 00000000000..bbdd248d6fa --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.fir.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE + +fun test() { + val x: Int? = 20 + if (x != null) { + } else { + if (true) return else return + } + x.and(1) // unsafe call +} diff --git a/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.kt b/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.kt new file mode 100644 index 00000000000..421f7c5fa25 --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.kt @@ -0,0 +1,11 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE + +fun test() { + val x: Int? = 20 + if (x != null) { + } else { + if (true) return else return + } + x.and(1) // unsafe call +} diff --git a/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.txt b/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.txt new file mode 100644 index 00000000000..93e27f34c8c --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.txt @@ -0,0 +1,3 @@ +package + +public fun test(): kotlin.Unit diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.kt index fb5f7956566..caeaef4566f 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/11.kt @@ -58,9 +58,9 @@ fun case_4() { */ fun case_5() { var x: Int? = null - if (x == try { x = 10; null } finally {} && x != null) { - x - x.inv() + if (x == try { x = 10; null } finally {} && x != null) { + x + x.inv() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.kt index 4afcf54e5ce..9c651f233c4 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/15.kt @@ -58,10 +58,10 @@ fun case_3() { */ fun case_4() { var x: Int? = null - if (x == try { x = 10; null } finally {} && x != null) { - x - x.inv() - println(1) + if (x == try { x = 10; null } finally {} && x != null) { + x + x.inv() + println(1) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt index 88abace7073..edb03a263bf 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/36.kt @@ -142,7 +142,7 @@ fun case_10(x: Any?, z: Any, b: Boolean?) { null -> throw Exception() } z === y || if (b == true) return else if (b === false) null!! else throw Exception() - x + x y y.equals(10) } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt index 3121eff8fa0..0c0a501ec6d 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/6.kt @@ -337,17 +337,17 @@ fun case_18(a: DeepObject.A.B.C.D.E.F.G.J?, b: Boolean) { val x = null val y = null - if (a != (if (b) x else y) || x !== a) { - a - a.equals(null) - a.propT - a.propAny - a.propNullableT - a.propNullableAny - a.funT() - a.funAny() - a.funNullableT() - a.funNullableAny() + if (a != (if (b) x else y) || x !== a) { + a + a.equals(null) + a.propT + a.propAny + a.propNullableT + a.propNullableAny + a.funT() + a.funAny() + a.funNullableT() + a.funNullableAny() } } @@ -1187,16 +1187,16 @@ fun case_66(x: Any?, z1: Nothing?, z2: Nothing?, b: Boolean) { if (x is ClassLevel3?) { if (x != if (b) { z1 } else { z2 } && x is ClassLevel4?) { if (x is ClassLevel5?) { - x - x.equals(null) - x.propT - x.propAny - x.propNullableT - x.propNullableAny - x.funT() - x.funAny() - x.funNullableT() - x.funNullableAny() + x + x.equals(null) + x.propT + x.propAny + x.propNullableT + x.propNullableAny + x.funT() + x.funAny() + x.funNullableT() + x.funNullableAny() } } } @@ -1249,16 +1249,16 @@ fun case_68(x: Any?, z: Nothing?) { */ fun case_69(x: Any?, z: Nothing?) { if (x is ClassLevel1? && x is ClassLevel2? && x is ClassLevel3? && x is ClassLevel4? && x != try { z } catch (e: Exception) { z } && x is ClassLevel5?) { - x - x.equals(null) - x.propT - x.propAny - x.propNullableT - x.propNullableAny - x.funT() - x.funAny() - x.funNullableT() - x.funNullableAny() + x + x.equals(null) + x.propT + x.propAny + x.propNullableT + x.propNullableAny + x.funT() + x.funAny() + x.funNullableT() + x.funNullableAny() } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index d2b9cc9d473..fce4842c474 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -17965,6 +17965,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.kt"); } + @TestMetadata("testNestedSpecialCalls.kt") + public void testTestNestedSpecialCalls() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.kt"); + } + @TestMetadata("TypeMismatchOnUnaryOperations.kt") public void testTypeMismatchOnUnaryOperations() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 25f94c0e443..a28ca15dfde 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -17955,6 +17955,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/regressions/SpecififcityByReceiver.kt"); } + @TestMetadata("testNestedSpecialCalls.kt") + public void testTestNestedSpecialCalls() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/testNestedSpecialCalls.kt"); + } + @TestMetadata("TypeMismatchOnUnaryOperations.kt") public void testTypeMismatchOnUnaryOperations() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/TypeMismatchOnUnaryOperations.kt");