From bd27ec840c0fc45ec7b0cf38cc80d8d2332dbb7c Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 14 Feb 2023 16:27:25 +0100 Subject: [PATCH] K1: report swallowed diagnostic about receiver type mismatch #KT-55056 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 12 ++++++++++ ...sticCompilerFE10TestDataTestGenerated.java | 12 ++++++++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 12 ++++++++++ ...siOldFrontendDiagnosticsTestGenerated.java | 12 ++++++++++ .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 5 ++++ .../DiagnosticReporterByTrackingStrategy.kt | 21 ++++++++++++---- .../components/PostponeArgumentsChecks.kt | 5 ++-- .../calls/components/ResolutionParts.kt | 8 ++++--- .../calls/components/SimpleArgumentsChecks.kt | 24 +++++++++++++------ .../model/ConstraintPositionAndErrorsImpl.kt | 5 +++- .../inconsistentTypeInference.diag.txt | 4 ++++ .../inconsistentTypeInference.fir.kt | 10 ++++++++ .../inconsistentTypeInference.fir.txt | 8 +++++++ .../inconsistentTypeInference.kt | 10 ++++++++ .../inconsistentTypeInference2.diag.txt | 3 +++ .../inconsistentTypeInference2.fir.kt | 9 +++++++ .../inconsistentTypeInference2.fir.txt | 8 +++++++ .../inconsistentTypeInference2.kt | 9 +++++++ .../extensionWithNonValuableConstraints.kt | 2 +- .../test/runners/DiagnosticTestGenerated.java | 12 ++++++++++ 21 files changed, 173 insertions(+), 19 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.diag.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.diag.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 5e4e9b077d4..c62d64e42eb 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -36604,6 +36604,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + @Test + @TestMetadata("inconsistentTypeInference.kt") + public void testInconsistentTypeInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt"); + } + + @Test + @TestMetadata("inconsistentTypeInference2.kt") + public void testInconsistentTypeInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt"); + } + @Test @TestMetadata("incorrectCalls.kt") public void testIncorrectCalls() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index f0972556e3a..ee7220f0b6c 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -36604,6 +36604,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + @Test + @TestMetadata("inconsistentTypeInference.kt") + public void testInconsistentTypeInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt"); + } + + @Test + @TestMetadata("inconsistentTypeInference2.kt") + public void testInconsistentTypeInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt"); + } + @Test @TestMetadata("incorrectCalls.kt") public void testIncorrectCalls() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 004e6d48ca0..0ebbf9fe009 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -36604,6 +36604,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + @Test + @TestMetadata("inconsistentTypeInference.kt") + public void testInconsistentTypeInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt"); + } + + @Test + @TestMetadata("inconsistentTypeInference2.kt") + public void testInconsistentTypeInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt"); + } + @Test @TestMetadata("incorrectCalls.kt") public void testIncorrectCalls() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 96a1a7d42b7..e710bc2e31d 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -36700,6 +36700,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + @Test + @TestMetadata("inconsistentTypeInference.kt") + public void testInconsistentTypeInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt"); + } + + @Test + @TestMetadata("inconsistentTypeInference2.kt") + public void testInconsistentTypeInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt"); + } + @Test @TestMetadata("incorrectCalls.kt") public void testIncorrectCalls() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index b220ed76324..f4af2e262df 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -915,6 +915,7 @@ public interface Errors { DiagnosticFactory2 TYPE_MISMATCH_WARNING_FOR_INCORRECT_CAPTURE_APPROXIMATION = DiagnosticFactory2.create(WARNING); DiagnosticFactory2 RECEIVER_TYPE_MISMATCH_WARNING_FOR_INCORRECT_CAPTURE_APPROXIMATION = DiagnosticFactory2.create(WARNING); + DiagnosticFactory2 RECEIVER_TYPE_MISMATCH = DiagnosticFactory2.create(ERROR); // Type inference diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index af52fae260c..a7c5770ff4c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -519,6 +519,11 @@ public class DefaultErrorMessages { "Extension receiver type mismatch: inferred type is {1} but {0} was expected. This warning will be an error soon. See https://youtrack.jetbrains.com/issue/KT-49404 for details", RENDER_TYPE, RENDER_TYPE ); + MAP.put( + RECEIVER_TYPE_MISMATCH, + "Constraint error in receiver type argument: inferred type is {1} but {0} was expected", + RENDER_TYPE, RENDER_TYPE + ); MAP.put(LOCAL_EXTENSION_PROPERTY, "Local extension properties are not allowed"); MAP.put(LOCAL_VARIABLE_WITH_GETTER, "Local variables are not allowed to have getters"); MAP.put(LOCAL_VARIABLE_WITH_SETTER, "Local variables are not allowed to have setters"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index bb8d109e5e7..ac1e0414e09 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -459,19 +459,22 @@ class DiagnosticReporterByTrackingStrategy( is ArgumentConstraintPosition<*> -> { reportArgumentConstraintErrorByPosition( error, position.argument as KotlinCallArgument, - isWarning, typeMismatchDiagnostic, report + isWarning, typeMismatchDiagnostic, + kotlinCall = null, report ) } is ReceiverConstraintPosition<*> -> { reportArgumentConstraintErrorByPosition( error, position.argument as KotlinCallArgument, - isWarning, typeMismatchDiagnostic, report + isWarning, typeMismatchDiagnostic, + kotlinCall = (position as ReceiverConstraintPositionImpl).kotlinCall, report ) } is LambdaArgumentConstraintPosition<*> -> { reportArgumentConstraintErrorByPosition( error, (position.lambda as ResolvedLambdaAtom).atom, - isWarning, typeMismatchDiagnostic, report + isWarning, typeMismatchDiagnostic, + kotlinCall = null, report ) } is BuilderInferenceExpectedTypeConstraintPosition -> { @@ -545,6 +548,7 @@ class DiagnosticReporterByTrackingStrategy( argument: KotlinCallArgument, isWarning: Boolean, typeMismatchDiagnostic: DiagnosticFactory2, + kotlinCall: KotlinCall?, report: (Diagnostic) -> Unit ) { if (argument is LambdaKotlinCallArgument) { @@ -562,8 +566,15 @@ class DiagnosticReporterByTrackingStrategy( } } - // TODO: FIXME (KT-55056) - val expression = argument.psiExpression ?: return + val expression = argument.psiExpression ?: run { + val psiCall = (kotlinCall as? PSIKotlinCall)?.psiCall ?: psiKotlinCall.psiCall + report( + RECEIVER_TYPE_MISMATCH.on( + psiCall.calleeExpression ?: psiCall.callElement, error.upperKotlinType, error.lowerKotlinType + ) + ) + return + } val deparenthesized = KtPsiUtil.safeDeparenthesize(expression) if (reportConstantTypeMismatch(error, deparenthesized)) return diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt index d7800c7c62d..57d4e6dedc4 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/PostponeArgumentsChecks.kt @@ -34,10 +34,11 @@ fun resolveKtPrimitive( diagnosticsHolder: KotlinDiagnosticsHolder, receiverInfo: ReceiverInfo, convertedType: UnwrappedType?, - inferenceSession: InferenceSession? + inferenceSession: InferenceSession?, + kotlinCall: KotlinCall? = null, ): ResolvedAtom = when (argument) { is SimpleKotlinCallArgument -> - checkSimpleArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, convertedType, inferenceSession) + checkSimpleArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, convertedType, inferenceSession, kotlinCall) is LambdaKotlinCallArgument -> preprocessLambdaArgument(csBuilder, argument, expectedType, diagnosticsHolder) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt index f9511aaa3d0..05c91720795 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/ResolutionParts.kt @@ -533,7 +533,8 @@ private fun ResolutionCandidate.resolveKotlinArgument( this, receiverInfo, convertedArgument?.unknownIntegerType?.unwrap(), - inferenceSession + inferenceSession, + receiverInfo.selectorCall ) addResolvedKtPrimitive(resolvedAtom) @@ -647,7 +648,7 @@ private fun ResolutionCandidate.getReceiverArgumentWithConstraintIfCompatible( val expectedTypeUnprepared = argument.getExpectedType(parameter, callComponents.languageVersionSettings) val expectedType = prepareExpectedType(expectedTypeUnprepared) val argumentType = captureFromTypeParameterUpperBoundIfNeeded(argument.receiver.stableType, expectedType) - val position = ReceiverConstraintPositionImpl(argument) + val position = ReceiverConstraintPositionImpl(argument, resolvedCall.atom) return if (csBuilder.isSubtypeConstraintCompatible(argumentType, expectedType, position)) ApplicableContextReceiverArgumentWithConstraint(argument, argumentType, expectedType, position) else null @@ -732,7 +733,8 @@ internal object CheckReceivers : ResolutionPart() { val receiverInfo = ReceiverInfo( isReceiver = true, shouldReportUnsafeCall = implicitInvokeState != ImplicitInvokeCheckStatus.UNSAFE_INVOKE_REPORTED, - reportUnsafeCallAsUnsafeImplicitInvoke = implicitInvokeState == ImplicitInvokeCheckStatus.INVOKE_ON_NOT_NULL_VARIABLE + reportUnsafeCallAsUnsafeImplicitInvoke = implicitInvokeState == ImplicitInvokeCheckStatus.INVOKE_ON_NOT_NULL_VARIABLE, + selectorCall = resolvedCall.atom ) resolveKotlinArgument(receiverArgument, receiverParameter, receiverInfo) diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt index 46d81f396d4..c800eaf40f8 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/components/SimpleArgumentsChecks.kt @@ -35,6 +35,7 @@ class ReceiverInfo( val isReceiver: Boolean, val shouldReportUnsafeCall: Boolean, // should not report if unsafe implicit invoke has been reported already val reportUnsafeCallAsUnsafeImplicitInvoke: Boolean, + val selectorCall: KotlinCall? = null, ) { init { assert(!reportUnsafeCallAsUnsafeImplicitInvoke || shouldReportUnsafeCall) { "Inconsistent receiver info" } @@ -52,11 +53,15 @@ fun checkSimpleArgument( diagnosticsHolder: KotlinDiagnosticsHolder, receiverInfo: ReceiverInfo, convertedType: UnwrappedType?, - inferenceSession: InferenceSession? + inferenceSession: InferenceSession?, + kotlinCall: KotlinCall? ): ResolvedAtom = when (argument) { - is ExpressionKotlinCallArgument -> checkExpressionArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo.isReceiver, convertedType) - is SubKotlinCallArgument -> checkSubCallArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, inferenceSession) - else -> unexpectedArgument(argument) + is ExpressionKotlinCallArgument -> + checkExpressionArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo.isReceiver, convertedType, kotlinCall) + is SubKotlinCallArgument -> + checkSubCallArgument(csBuilder, argument, expectedType, diagnosticsHolder, receiverInfo, inferenceSession) + else -> + unexpectedArgument(argument) } private fun checkExpressionArgument( @@ -65,7 +70,8 @@ private fun checkExpressionArgument( expectedType: UnwrappedType?, diagnosticsHolder: KotlinDiagnosticsHolder, isReceiver: Boolean, - convertedType: UnwrappedType? + convertedType: UnwrappedType?, + kotlinCall: KotlinCall? ): ResolvedAtom { val resolvedExpression = ResolvedExpressionAtom(expressionArgument) if (expectedType == null) return resolvedExpression @@ -93,7 +99,9 @@ private fun checkExpressionArgument( return null } - val position = if (isReceiver) ReceiverConstraintPositionImpl(expressionArgument) else ArgumentConstraintPositionImpl(expressionArgument) + val position = + if (isReceiver) ReceiverConstraintPositionImpl(expressionArgument, kotlinCall) + else ArgumentConstraintPositionImpl(expressionArgument) // Used only for arguments with @NotNull annotation if (expectedType is NotNullTypeParameter && argumentType.isMarkedNullable) { @@ -188,7 +196,9 @@ private fun checkSubCallArgument( if (expectedType == null) return subCallResult val expectedNullableType = expectedType.makeNullableAsSpecified(true) - val position = if (receiverInfo.isReceiver) ReceiverConstraintPositionImpl(subCallArgument) else ArgumentConstraintPositionImpl(subCallArgument) + val position = + if (receiverInfo.isReceiver) ReceiverConstraintPositionImpl(subCallArgument, subCallArgument.callResult.resultCallAtom.atom) + else ArgumentConstraintPositionImpl(subCallArgument) // subArgument cannot has stable smartcast // return type can contains fixed type variables diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt index 9edb4b0478f..99247251895 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/model/ConstraintPositionAndErrorsImpl.kt @@ -39,7 +39,10 @@ class ArgumentConstraintPositionImpl(argument: KotlinCallArgument) : ArgumentCon class CallableReferenceConstraintPositionImpl(val callableReferenceCall: CallableReferenceKotlinCall) : CallableReferenceConstraintPosition(callableReferenceCall) -class ReceiverConstraintPositionImpl(argument: KotlinCallArgument) : ReceiverConstraintPosition(argument) +class ReceiverConstraintPositionImpl( + argument: KotlinCallArgument, + val kotlinCall: KotlinCall? +) : ReceiverConstraintPosition(argument) class FixVariableConstraintPositionImpl( variable: TypeVariableMarker, diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.diag.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.diag.txt new file mode 100644 index 00000000000..2bc19155f43 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.diag.txt @@ -0,0 +1,4 @@ +/inconsistentTypeInference.kt:7:17: error: constraint error in receiver type argument: inferred type is String but Int was expected + println(plus(1)[0]) + ^ + diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.kt new file mode 100644 index 00000000000..a54823de9ad --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.kt @@ -0,0 +1,10 @@ +// !RENDER_DIAGNOSTICS_FULL_TEXT +// FIR_DUMP + +fun foo() { + buildList { + add("Boom") + println(plus(1)[0]) + } +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt new file mode 100644 index 00000000000..82139b95be6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.fir.txt @@ -0,0 +1,8 @@ +FILE: inconsistentTypeInference.fir.kt + public final fun foo(): R|kotlin/Unit| { + R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + this@R|special/anonymous|.R|SubstitutionOverride|(String(Boom)) + R|kotlin/io/println|(this@R|special/anonymous|.R|kotlin/collections/plus|(Int(1)).R|SubstitutionOverride|(Int(0))) + } + ) + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt new file mode 100644 index 00000000000..0be8c9d76d7 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt @@ -0,0 +1,10 @@ +// !RENDER_DIAGNOSTICS_FULL_TEXT +// FIR_DUMP + +fun foo() { + buildList { + add("Boom") + println(plus(1)[0]) + } +} + diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.diag.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.diag.txt new file mode 100644 index 00000000000..ae8a2a0cbc4 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.diag.txt @@ -0,0 +1,3 @@ +/inconsistentTypeInference2.kt:7:17: error: type mismatch: inferred type is String but Int was expected + println(this.plus(1)[0]) + ^ diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.kt new file mode 100644 index 00000000000..914030acb36 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.kt @@ -0,0 +1,9 @@ +// !RENDER_DIAGNOSTICS_FULL_TEXT +// FIR_DUMP + +fun bar() { + buildList { + add("Boom") + println(this.plus(1)[0]) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt new file mode 100644 index 00000000000..7f74bfb99e0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.fir.txt @@ -0,0 +1,8 @@ +FILE: inconsistentTypeInference2.fir.kt + public final fun bar(): R|kotlin/Unit| { + R|kotlin/collections/buildList|( = buildList@fun R|kotlin/collections/MutableList|.(): R|kotlin/Unit| { + this@R|special/anonymous|.R|SubstitutionOverride|(String(Boom)) + R|kotlin/io/println|(this@R|special/anonymous|.R|kotlin/collections/plus|(Int(1)).R|SubstitutionOverride|(Int(0))) + } + ) + } diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt new file mode 100644 index 00000000000..c2c644b53cc --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt @@ -0,0 +1,9 @@ +// !RENDER_DIAGNOSTICS_FULL_TEXT +// FIR_DUMP + +fun bar() { + buildList { + add("Boom") + println(this.plus(1)[0]) + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.kt index da9ed1e5248..7f2e9776344 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionWithNonValuableConstraints.kt @@ -52,7 +52,7 @@ val test6 = generate { val test7 = generate { yield("baz") - genericExtension() + genericExtension() } val test8 = generate { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 4d643a4ba2b..d4cff3529ab 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -37448,6 +37448,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + @Test + @TestMetadata("inconsistentTypeInference.kt") + public void testInconsistentTypeInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference.kt"); + } + + @Test + @TestMetadata("inconsistentTypeInference2.kt") + public void testInconsistentTypeInference2() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inconsistentTypeInference2.kt"); + } + @Test @TestMetadata("incorrectCalls.kt") public void testIncorrectCalls() throws Exception {