diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java index 8b68a7ef490..2cb316040be 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -10564,6 +10564,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.kt"); } + @TestMetadata("iltInsideSeveralCalls.kt") + public void testIltInsideSeveralCalls() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.kt"); + } + @TestMetadata("inferenceWithUpperBoundsInLambda.kt") public void testInferenceWithUpperBoundsInLambda() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.kt"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index bca57eba32c..7a49965b673 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -279,12 +279,7 @@ class KotlinToResolvedCallTransformer( } // todo very beginning code - fun runArgumentsChecks( - context: BasicCallResolutionContext, - trace: BindingTrace, - resolvedCall: NewResolvedCallImpl<*>, - ) { - + fun runArgumentsChecks(context: BasicCallResolutionContext, resolvedCall: NewResolvedCallImpl<*>) { for (valueArgument in resolvedCall.call.valueArguments) { val argumentMapping = resolvedCall.getArgumentMapping(valueArgument!!) val parameter: ValueParameterDescriptor? diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt index 98196ae9703..5d2ed674d6e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/ResolvedAtomCompleter.kt @@ -77,7 +77,6 @@ class ResolvedAtomCompleter( is ResolvedLambdaAtom -> completeLambda(resolvedAtom) is ResolvedCallAtom -> completeResolvedCall(resolvedAtom, emptyList()) is ResolvedSubCallArgument -> completeSubCallArgument(resolvedAtom) - is PartialCallResolutionResult -> completeResolvedCall(resolvedAtom.resultCallAtom, resolvedAtom.diagnostics) } } @@ -102,20 +101,24 @@ class ResolvedAtomCompleter( } fun completeResolvedCall(resolvedCallAtom: ResolvedCallAtom, diagnostics: Collection): ResolvedCall<*>? { + val diagnosticsFromPartiallyResolvedCall = extractDiagnosticsFromPartiallyResolvedCall(resolvedCallAtom) + clearPartiallyResolvedCall(resolvedCallAtom) if (resolvedCallAtom.atom.psiKotlinCall is PSIKotlinCallForVariable) return null + val allDiagnostics = diagnostics + diagnosticsFromPartiallyResolvedCall + val resolvedCall = kotlinToResolvedCallTransformer.transformToResolvedCall( resolvedCallAtom, topLevelTrace, resultSubstitutor, - diagnostics + allDiagnostics ) val lastCall = if (resolvedCall is VariableAsFunctionResolvedCall) resolvedCall.functionCall else resolvedCall if (ErrorUtils.isError(resolvedCall.candidateDescriptor)) { - kotlinToResolvedCallTransformer.runArgumentsChecks(topLevelCallContext, topLevelTrace, lastCall as NewResolvedCallImpl<*>) + kotlinToResolvedCallTransformer.runArgumentsChecks(topLevelCallContext, lastCall as NewResolvedCallImpl<*>) checkMissingReceiverSupertypes(resolvedCall, missingSupertypesResolver, topLevelTrace) return resolvedCall } @@ -135,11 +138,11 @@ class ResolvedAtomCompleter( kotlinToResolvedCallTransformer.bind(topLevelTrace, resolvedCall) - kotlinToResolvedCallTransformer.runArgumentsChecks(topLevelCallContext, topLevelTrace, lastCall as NewResolvedCallImpl<*>) + kotlinToResolvedCallTransformer.runArgumentsChecks(topLevelCallContext, lastCall as NewResolvedCallImpl<*>) kotlinToResolvedCallTransformer.runCallCheckers(resolvedCall, callCheckerContext) kotlinToResolvedCallTransformer.runAdditionalReceiversCheckers(resolvedCall, topLevelCallContext) - kotlinToResolvedCallTransformer.reportDiagnostics(topLevelCallContext, topLevelTrace, resolvedCall, diagnostics) + kotlinToResolvedCallTransformer.reportDiagnostics(topLevelCallContext, topLevelTrace, resolvedCall, allDiagnostics) return resolvedCall } @@ -160,6 +163,13 @@ class ResolvedAtomCompleter( } } + private fun extractDiagnosticsFromPartiallyResolvedCall(resolvedCallAtom: ResolvedCallAtom): Set { + val psiCall = KotlinToResolvedCallTransformer.keyForPartiallyResolvedCall(resolvedCallAtom) + val partialCallContainer = topLevelTrace[BindingContext.ONLY_RESOLVED_CALL, psiCall] + + return partialCallContainer?.result?.diagnostics.orEmpty().toSet() + } + private fun clearPartiallyResolvedCall(resolvedCallAtom: ResolvedCallAtom) { val psiCall = KotlinToResolvedCallTransformer.keyForPartiallyResolvedCall(resolvedCallAtom) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt index d59df9b6175..d2dd01d3c8c 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/KotlinCallCompleter.kt @@ -222,7 +222,7 @@ class KotlinCallCompleter( forwardToInferenceSession: Boolean = false ): CallResolutionResult { val systemStorage = getSystem().asReadOnlyStorage() - val allDiagnostics = diagnosticsHolder.getDiagnostics() + this.diagnosticsFromResolutionParts + val allDiagnostics = diagnosticsHolder.getDiagnostics() + diagnosticsFromResolutionParts if (isErrorCandidate()) { return ErrorCallResolutionResult(resolvedCall, allDiagnostics, systemStorage) diff --git a/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.kt b/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.kt index 9365da850d2..7bc217846ee 100644 --- a/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.kt +++ b/compiler/testData/diagnostics/tests/generics/tpAsReified/InFunction.kt @@ -14,5 +14,5 @@ fun main() { val b: Int = f() f() - val с: A = id(f()) + val с: A = id(f()) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.kt b/compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.kt new file mode 100644 index 00000000000..7be3dd8acae --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.kt @@ -0,0 +1,13 @@ +// FIR_IDENTICAL +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -UNUSED_EXPRESSION + +fun consumeLongAndMaterialize(x: Long): T = null as T +fun consumeAny(x: Any) = x + +fun main() { + consumeAny(consumeLongAndMaterialize(3 * 1000)) + + if (true) { + consumeLongAndMaterialize(3 * 1000) + } else true +} diff --git a/compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.txt b/compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.txt new file mode 100644 index 00000000000..0bfcc2a6fc1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.txt @@ -0,0 +1,5 @@ +package + +public fun consumeAny(/*0*/ x: kotlin.Any): kotlin.Any +public fun consumeLongAndMaterialize(/*0*/ x: kotlin.Long): T +public fun main(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.kt b/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.kt index 75473e3d5a3..c3c97394c22 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/anonymousFunction.kt @@ -20,5 +20,5 @@ fun testFunctions() { fun testNestedCalls() { id(inferFromLambda { materialize() }) id(inferFromLambda(fun() = materialize())) - id(inferFromLambda2(fun() = materialize())) + id(inferFromLambda2(fun() = materialize())) } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt index b7ca2e10762..70924486f1a 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/lackOfDeepIncorporation.kt @@ -30,7 +30,7 @@ class Foo { other1.product( other2.product( other3.product( - bar { d -> { c -> { b -> { a -> function(a, b, c, d) } } } } + bar { d -> { c -> { b -> { a -> function(a, b, c, d) } } } } ) ) ) @@ -43,7 +43,7 @@ class Foo { other1.product( other2.product( other3.product( - other4.product( + other4.product( bar { e -> { d -> { c -> { b -> { a -> function(a, b, c, d, e) } } } } } ) ) diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/discriminateNothingForReifiedParameter.kt b/compiler/testData/diagnostics/tests/inference/nothingType/discriminateNothingForReifiedParameter.kt index 71d26d1ee81..f36a1ec8659 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/discriminateNothingForReifiedParameter.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/discriminateNothingForReifiedParameter.kt @@ -35,7 +35,7 @@ fun test5(): Bound? = select( fun test6() { select( null, - materializeReified() + materializeReified() ) } @@ -48,6 +48,6 @@ fun test7(): Bound? = fun test8() { select( null, - materializeReifiedUnbound() + materializeReifiedUnbound() ) } diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt index e385c67e256..e4c4300bfb8 100644 --- a/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt +++ b/compiler/testData/diagnostics/tests/inference/nothingType/reifiedParameterWithRecursiveBound.kt @@ -28,7 +28,7 @@ inline fun > testIn(): T { // Unexpected behaviour inline fun > testOut(): T { return try { - outBound() + outBound() } catch (ex: Exception) { throw Exception() } diff --git a/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.kt b/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.kt index 8fa76806ef3..6b103f7e083 100644 --- a/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.kt +++ b/compiler/testData/diagnostics/tests/regressions/correctResultSubstitutorForErrorCandidate.kt @@ -2,7 +2,7 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER fun test(a: Int, b: Boolean) { - bar(a.foo(b)) + bar(a.foo(b)) } fun T.foo(l: (T) -> R): R = TODO() diff --git a/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt b/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt index 7679346bd45..91feabb9dc3 100644 --- a/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt +++ b/compiler/testData/diagnostics/tests/resolve/specialConstructions/constantsInIf.kt @@ -8,7 +8,7 @@ fun test() { 2 }) - bar(1 ?: 2) + bar(1 ?: 2) } fun bar(s: String) = s \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.kt b/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.kt index ecd73a325b1..4e5c11e9958 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/ArrayOfNothing.kt @@ -51,6 +51,6 @@ fun test6() = foo() class B(val array: Array) -fun bar() = B>(arrayOf()) +fun bar() = B>(arrayOf()) fun test7() = bar() diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.kt index 00348297f80..a4fbc2da293 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/javaAnnotationWithVarargArgument.kt @@ -6,6 +6,6 @@ public @interface A { } // FILE: b.kt -@A(*arrayOf(1, "b")) +@A(*arrayOf(1, "b")) fun test() { } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.kt index 87eb60ef350..f19fe4b86e5 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/annotationWithVarargParameter/kotlinAnnotationWithVarargArgument.kt @@ -2,6 +2,6 @@ annotation class B(vararg val args: String) -@B(*arrayOf(1, "b")) +@B(*arrayOf(1, "b")) fun test() { } diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt index 0183d191c53..3d45621274f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsInVariance.kt @@ -14,7 +14,7 @@ class MyClass1 @Ann1(arrayOf(Any::class)) class MyClass1a -@Ann1(arrayOf(B1::class)) +@Ann1(arrayOf(B1::class)) class MyClass2 annotation class Ann2(val arg: Array>) @@ -25,5 +25,5 @@ class MyClass3 @Ann2(arrayOf(B1::class)) class MyClass4 -@Ann2(arrayOf(B2::class)) +@Ann2(arrayOf(B2::class)) class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt index dc5ca411f21..b0f09ecd02e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/kClass/kClassArrayInAnnotationsOutVariance.kt @@ -11,7 +11,7 @@ annotation class Ann1(val arg: Array>) @Ann1(arrayOf(A::class)) class MyClass1 -@Ann1(arrayOf(Any::class)) +@Ann1(arrayOf(Any::class)) class MyClass1a @Ann1(arrayOf(B1::class)) @@ -19,11 +19,11 @@ class MyClass2 annotation class Ann2(val arg: Array>) -@Ann2(arrayOf(A::class)) +@Ann2(arrayOf(A::class)) class MyClass3 @Ann2(arrayOf(B1::class)) class MyClass4 -@Ann2(arrayOf(B2::class)) +@Ann2(arrayOf(B2::class)) class MyClass5 diff --git a/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.kt b/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.kt index b502f0241cc..547e568f876 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/reified/arrayConstruction.kt @@ -9,8 +9,8 @@ fun fail2(): Array = ok1 { Array<T>(1) { fun ok3(block: () -> Array): Array = ok1 { block() } inline fun ok4(): Array = ok1 { Array(1) { null!! } } -fun fail3(block: () -> T): Pair, Array> = Pair(arrayOf( - block()), arrayOf() +fun fail3(block: () -> T): Pair, Array> = Pair(arrayOf( + block()), arrayOf() ) inline fun ok5(block: () -> T): Pair, Array> = Pair( arrayOf(block()), arrayOf() diff --git a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt index 25140a42cbc..7bca0381a93 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/tryCatch/tryExpression.kt @@ -30,6 +30,6 @@ fun test2(): Map = run { try { emptyMap() } catch (e: ExcA) { - mapOf("" to "") + mapOf("" to "") } } \ No newline at end of file diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt index 76419b66c4f..3b08f028da2 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/try-expression/p-8/neg/1.1.kt @@ -47,7 +47,6 @@ fun case2() { /* * TESTCASE NUMBER: 3 - * UNEXPECTED BEHAVIOUR * ISSUES: KT-35494 */ fun case3() { @@ -56,9 +55,9 @@ fun case3() { throwExceptionA(false) A(2) } catch (e: ExcA) { - A(null) //diag duplication + A(null) //diag duplication } catch (e: ExcB) { - B(null) //diag duplication + B(null) //diag duplication } } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 8427a89ee0b..ad3afc99013 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10571,6 +10571,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.kt"); } + @TestMetadata("iltInsideSeveralCalls.kt") + public void testIltInsideSeveralCalls() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.kt"); + } + @TestMetadata("inferenceWithUpperBoundsInLambda.kt") public void testInferenceWithUpperBoundsInLambda() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index e989bf3a23d..1331ab17da1 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10566,6 +10566,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/commonSystem/genericCandidateInGenericClass.kt"); } + @TestMetadata("iltInsideSeveralCalls.kt") + public void testIltInsideSeveralCalls() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/commonSystem/iltInsideSeveralCalls.kt"); + } + @TestMetadata("inferenceWithUpperBoundsInLambda.kt") public void testInferenceWithUpperBoundsInLambda() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/commonSystem/inferenceWithUpperBoundsInLambda.kt");