From 37d163d417bfe8ecd2e4baea3e5651906c96e150 Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 11 Jan 2022 15:22:03 +0300 Subject: [PATCH] [FE 1.0] Don't lose diagnostics during lambda analysis at the overload resolution by return type stage ^KT-49658 Fixed --- ...CompilerTestFE10TestdataTestGenerated.java | 12 ++++++ ...irOldFrontendDiagnosticsTestGenerated.java | 12 ++++++ ...DiagnosticsWithLightTreeTestGenerated.java | 12 ++++++ .../jetbrains/kotlin/diagnostics/Errors.java | 1 + .../rendering/DefaultErrorMessages.java | 1 + .../DiagnosticReporterByTrackingStrategy.kt | 42 +++++++++++++------ .../calls/components/KotlinCallCompleter.kt | 24 ++++++++++- .../calls/components/SimpleArgumentsChecks.kt | 4 +- .../calls/model/KotlinCallDiagnostics.kt | 37 +++++++++++++--- .../tests/inference/kt49658.fir.kt | 16 +++++++ .../diagnostics/tests/inference/kt49658.kt | 16 +++++++ .../diagnostics/tests/inference/kt49658.txt | 5 +++ .../tests/inference/kt49658Strict.fir.kt | 17 ++++++++ .../tests/inference/kt49658Strict.kt | 17 ++++++++ .../tests/inference/kt49658Strict.txt | 4 ++ .../test/runners/DiagnosticTestGenerated.java | 12 ++++++ .../kotlin/config/LanguageVersionSettings.kt | 1 + 17 files changed, 212 insertions(+), 21 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/kt49658.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt49658.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt49658.txt create mode 100644 compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt49658Strict.kt create mode 100644 compiler/testData/diagnostics/tests/inference/kt49658Strict.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 0fe79f6db61..3726c3bcbb5 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -13647,6 +13647,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt"); } + @Test + @TestMetadata("kt49658.kt") + public void testKt49658() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658.kt"); + } + + @Test + @TestMetadata("kt49658Strict.kt") + public void testKt49658Strict() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 2d509aef2db..a1c5b1e2b00 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -13647,6 +13647,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt"); } + @Test + @TestMetadata("kt49658.kt") + public void testKt49658() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658.kt"); + } + + @Test + @TestMetadata("kt49658Strict.kt") + public void testKt49658Strict() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 890f136ca1c..a6568ba5cef 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -13647,6 +13647,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt"); } + @Test + @TestMetadata("kt49658.kt") + public void testKt49658() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658.kt"); + } + + @Test + @TestMetadata("kt49658Strict.kt") + public void testKt49658Strict() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() 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 ec5ceb89aa7..3cc87a1fab6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -1103,6 +1103,7 @@ public interface Errors { DiagnosticFactory1.create(ERROR); DiagnosticFactory1 ILLEGAL_ESCAPE = DiagnosticFactory1.create(ERROR, CUT_CHAR_QUOTES); DiagnosticFactory1 NULL_FOR_NONNULL_TYPE = DiagnosticFactory1.create(ERROR); + DiagnosticFactory1 NULL_FOR_NONNULL_TYPE_WARNING = DiagnosticFactory1.create(WARNING); DiagnosticFactory0 ILLEGAL_ESCAPE_SEQUENCE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 UNSIGNED_LITERAL_WITHOUT_DECLARATIONS_ON_CLASSPATH = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 SIGNED_CONSTANT_CONVERTED_TO_UNSIGNED = DiagnosticFactory0.create(ERROR); 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 d8828cfa148..a7b698f2203 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -632,6 +632,7 @@ public class DefaultErrorMessages { MAP.put(TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL, "Too many characters in a character literal ''{0}''", ELEMENT_TEXT); MAP.put(ILLEGAL_ESCAPE, "Illegal escape: ''{0}''", ELEMENT_TEXT); MAP.put(NULL_FOR_NONNULL_TYPE, "Null can not be a value of a non-null type {0}", RENDER_TYPE); + MAP.put(NULL_FOR_NONNULL_TYPE_WARNING, "Null can not be a value of a non-null type {0}", RENDER_TYPE); MAP.put(ELSE_MISPLACED_IN_WHEN, "'else' entry must be the last one in a when-expression"); MAP.put(REDUNDANT_ELSE_IN_WHEN, "'when' is exhaustive so 'else' is redundant here"); 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 7acbd31ad20..2d4d4a27139 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -215,18 +215,14 @@ class DiagnosticReporterByTrackingStrategy( } } - ArgumentNullabilityMismatchDiagnostic::class.java -> { - require(diagnostic is ArgumentNullabilityMismatchDiagnostic) - val expression = callArgument.safeAs()?.valueArgument?.getArgumentExpression()?.let { - KtPsiUtil.deparenthesize(it) ?: it - } - if (expression != null) { - if (expression.isNull() && expression is KtConstantExpression) { - trace.reportDiagnosticOnce(NULL_FOR_NONNULL_TYPE.on(expression, diagnostic.expectedType)) - } else { - trace.report(TYPE_MISMATCH.on(expression, diagnostic.expectedType, diagnostic.actualType)) - } - } + ArgumentNullabilityErrorDiagnostic::class.java -> { + require(diagnostic is ArgumentNullabilityErrorDiagnostic) + reportNullabilityMismatchDiagnostic(callArgument, diagnostic) + } + + ArgumentNullabilityWarningDiagnostic::class.java -> { + require(diagnostic is ArgumentNullabilityWarningDiagnostic) + reportNullabilityMismatchDiagnostic(callArgument, diagnostic) } CallableReferencesDefaultArgumentUsed::class.java -> { @@ -582,6 +578,27 @@ class DiagnosticReporterByTrackingStrategy( } } + private fun reportNullabilityMismatchDiagnostic(callArgument: KotlinCallArgument, diagnostic: ArgumentNullabilityMismatchDiagnostic) { + val expression = callArgument.safeAs()?.valueArgument?.getArgumentExpression()?.let { + KtPsiUtil.deparenthesize(it) ?: it + } + if (expression != null) { + if (expression.isNull() && expression is KtConstantExpression) { + val factory = when (diagnostic) { + is ArgumentNullabilityErrorDiagnostic -> NULL_FOR_NONNULL_TYPE + is ArgumentNullabilityWarningDiagnostic -> NULL_FOR_NONNULL_TYPE_WARNING + } + trace.reportDiagnosticOnce(factory.on(expression, diagnostic.expectedType)) + } else { + val factory = when (diagnostic) { + is ArgumentNullabilityErrorDiagnostic -> TYPE_MISMATCH + is ArgumentNullabilityWarningDiagnostic -> TYPE_MISMATCH_WARNING + } + trace.report(factory.on(expression, diagnostic.expectedType, diagnostic.actualType)) + } + } + } + private fun reportNotEnoughInformationForTypeParameterForSpecialCall( resolvedAtom: ResolvedCallAtom, error: NotEnoughInformationForTypeParameterImpl @@ -622,7 +639,6 @@ class DiagnosticReporterByTrackingStrategy( || it.constructor == uninferredTypeVariable.freshTypeConstructor(typeSystemContext) } - @OptIn(ExperimentalStdlibApi::class) private fun getSubResolvedAtomsOfSpecialCallToReportUninferredTypeParameter( resolvedAtom: ResolvedAtom, uninferredTypeVariable: TypeVariableMarker 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 48e82c4c7d1..10320829315 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 @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.resolve.calls.components import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate @@ -31,7 +32,8 @@ import org.jetbrains.kotlin.utils.addToStdlib.same class KotlinCallCompleter( private val postponedArgumentsAnalyzer: PostponedArgumentsAnalyzer, private val kotlinConstraintSystemCompleter: KotlinConstraintSystemCompleter, - private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle + private val trivialConstraintTypeInferenceOracle: TrivialConstraintTypeInferenceOracle, + private val languageVersionSettings: LanguageVersionSettings ) { fun runCompletion( @@ -127,6 +129,7 @@ class KotlinCallCompleter( ConstraintSystemCompletionMode.FULL, diagnosticHolderForLambda, ) + propagateLambdaAnalysisDiagnostics(diagnosticHolderForLambda, firstCandidate) while (iterator.hasNext()) { val (candidate, atom) = iterator.next() @@ -137,6 +140,7 @@ class KotlinCallCompleter( ConstraintSystemCompletionMode.FULL, diagnosticHolderForLambda ) + propagateLambdaAnalysisDiagnostics(diagnosticHolderForLambda, candidate) } val errorCandidates = mutableSetOf() @@ -155,6 +159,24 @@ class KotlinCallCompleter( } } + private fun propagateLambdaAnalysisDiagnostics( + diagnosticHolder: KotlinDiagnosticsHolder.SimpleHolder, + candidate: SimpleResolutionCandidate + ) { + val dontLoseDiagnosticsDuringOverloadResolutionByReturnType = + languageVersionSettings.supportsFeature(LanguageFeature.DontLoseDiagnosticsDuringOverloadResolutionByReturnType) + + for (diagnostic in diagnosticHolder.getDiagnostics()) { + if (diagnostic is TransformableToWarning<*>) { + val transformedDiagnostic = + if (dontLoseDiagnosticsDuringOverloadResolutionByReturnType) diagnostic else diagnostic.transformToWarning() + if (transformedDiagnostic != null) { + candidate.addDiagnostic(transformedDiagnostic) + } + } + } + } + private fun SimpleResolutionCandidate.getInputTypesOfLambdaAtom(atom: ResolvedLambdaAtom): List { val result = mutableListOf() val substitutor = getSystem().getBuilder().buildCurrentSubstitutor() 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 390160f590b..46d81f396d4 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 @@ -85,7 +85,7 @@ private fun checkExpressionArgument( if (argumentType.isMarkedNullable) { if (csBuilder.addSubtypeConstraintIfCompatible(argumentType, actualExpectedType, position)) return null if (csBuilder.addSubtypeConstraintIfCompatible(argumentType.makeNotNullable(), actualExpectedType, position)) { - return ArgumentNullabilityMismatchDiagnostic(actualExpectedType, argumentType, expressionArgument) + return ArgumentNullabilityErrorDiagnostic(actualExpectedType, argumentType, expressionArgument) } } @@ -97,7 +97,7 @@ private fun checkExpressionArgument( // Used only for arguments with @NotNull annotation if (expectedType is NotNullTypeParameter && argumentType.isMarkedNullable) { - diagnosticsHolder.addDiagnostic(ArgumentNullabilityMismatchDiagnostic(expectedType, argumentType, expressionArgument)) + diagnosticsHolder.addDiagnostic(ArgumentNullabilityErrorDiagnostic(expectedType, argumentType, expressionArgument)) } if (expressionArgument.isSafeCall) { diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt index c76139bf660..9230b276926 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/model/KotlinCallDiagnostics.kt @@ -23,12 +23,18 @@ import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.resolve.calls.components.candidate.ResolutionCandidate import org.jetbrains.kotlin.resolve.calls.components.candidate.CallableReferenceResolutionCandidate import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintSystemError +import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintError import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintWarning +import org.jetbrains.kotlin.resolve.calls.inference.model.transformToWarning import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability import org.jetbrains.kotlin.resolve.calls.tower.CandidateApplicability.* import org.jetbrains.kotlin.types.TypeConstructor import org.jetbrains.kotlin.types.UnwrappedType +interface TransformableToWarning { + fun transformToWarning(): T? +} + abstract class InapplicableArgumentDiagnostic : KotlinCallDiagnostic(INAPPLICABLE) { abstract val argument: KotlinCallArgument @@ -227,11 +233,29 @@ class NonApplicableCallForBuilderInferenceDiagnostic(val kotlinCall: KotlinCall) } } -class ArgumentNullabilityMismatchDiagnostic( - val expectedType: UnwrappedType, - val actualType: UnwrappedType, +sealed interface ArgumentNullabilityMismatchDiagnostic { + val expectedType: UnwrappedType + val actualType: UnwrappedType val expressionArgument: ExpressionKotlinCallArgument -) : KotlinCallDiagnostic(UNSAFE_CALL) { +} + +class ArgumentNullabilityErrorDiagnostic( + override val expectedType: UnwrappedType, + override val actualType: UnwrappedType, + override val expressionArgument: ExpressionKotlinCallArgument +) : KotlinCallDiagnostic(UNSAFE_CALL), TransformableToWarning, ArgumentNullabilityMismatchDiagnostic { + override fun report(reporter: DiagnosticReporter) { + reporter.onCallArgument(expressionArgument, this) + } + + override fun transformToWarning() = ArgumentNullabilityWarningDiagnostic(expectedType, actualType, expressionArgument) +} + +class ArgumentNullabilityWarningDiagnostic( + override val expectedType: UnwrappedType, + override val actualType: UnwrappedType, + override val expressionArgument: ExpressionKotlinCallArgument +) : KotlinCallDiagnostic(RESOLVED), ArgumentNullabilityMismatchDiagnostic { override fun report(reporter: DiagnosticReporter) { reporter.onCallArgument(expressionArgument, this) } @@ -287,8 +311,11 @@ class MultipleArgumentsApplicableForContextReceiver(val receiverDescriptor: Rece class KotlinConstraintSystemDiagnostic( val error: ConstraintSystemError -) : KotlinCallDiagnostic(error.applicability) { +) : KotlinCallDiagnostic(error.applicability), TransformableToWarning { override fun report(reporter: DiagnosticReporter) = reporter.constraintError(error) + + override fun transformToWarning(): KotlinConstraintSystemDiagnostic? = + if (error is NewConstraintError) KotlinConstraintSystemDiagnostic(error.transformToWarning()) else null } val KotlinCallDiagnostic.constraintSystemError: ConstraintSystemError? diff --git a/compiler/testData/diagnostics/tests/inference/kt49658.fir.kt b/compiler/testData/diagnostics/tests/inference/kt49658.fir.kt new file mode 100644 index 00000000000..f8aa082dca8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49658.fir.kt @@ -0,0 +1,16 @@ +// WITH_STDLIB + +fun doTheMapThing1(elements: List): List { + return elements.flatMap { + when (it) { // NullPointerException + is String -> listOf("Yeah") + else -> null + } + } +} + +fun doTheMapThing2(elements: List): List { + return elements.flatMap { + if (it is String) listOf("Yeah") else null // it's OK with `if` + } +} diff --git a/compiler/testData/diagnostics/tests/inference/kt49658.kt b/compiler/testData/diagnostics/tests/inference/kt49658.kt new file mode 100644 index 00000000000..902ae5fd36f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49658.kt @@ -0,0 +1,16 @@ +// WITH_STDLIB + +fun doTheMapThing1(elements: List): List { + return elements.flatMap { + when (it) { // NullPointerException + is String -> listOf("Yeah") + else -> null + } + } +} + +fun doTheMapThing2(elements: List): List { + return elements.flatMap { + if (it is String) listOf("Yeah") else null // it's OK with `if` + } +} diff --git a/compiler/testData/diagnostics/tests/inference/kt49658.txt b/compiler/testData/diagnostics/tests/inference/kt49658.txt new file mode 100644 index 00000000000..954030af252 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49658.txt @@ -0,0 +1,5 @@ +package + +public fun doTheMapThing1(/*0*/ elements: kotlin.collections.List): kotlin.collections.List +public fun doTheMapThing2(/*0*/ elements: kotlin.collections.List): kotlin.collections.List + diff --git a/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt b/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt new file mode 100644 index 00000000000..435095978c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49658Strict.fir.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +DontLoseDiagnosticsDuringOverloadResolutionByReturnType +// WITH_STDLIB + +fun doTheMapThing1(elements: List): List { + return elements.flatMap { + when (it) { // NullPointerException + is String -> listOf("Yeah") + else -> null + } + } +} + +fun doTheMapThing2(elements: List): List { + return elements.flatMap { + if (it is String) listOf("Yeah") else null // it's OK with `if` + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/kt49658Strict.kt b/compiler/testData/diagnostics/tests/inference/kt49658Strict.kt new file mode 100644 index 00000000000..6a31bf536ee --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49658Strict.kt @@ -0,0 +1,17 @@ +// !LANGUAGE: +DontLoseDiagnosticsDuringOverloadResolutionByReturnType +// WITH_STDLIB + +fun doTheMapThing1(elements: List): List { + return elements.flatMap { + when (it) { // NullPointerException + is String -> listOf("Yeah") + else -> null + } + } +} + +fun doTheMapThing2(elements: List): List { + return elements.flatMap { + if (it is String) listOf("Yeah") else null // it's OK with `if` + } +} diff --git a/compiler/testData/diagnostics/tests/inference/kt49658Strict.txt b/compiler/testData/diagnostics/tests/inference/kt49658Strict.txt new file mode 100644 index 00000000000..fe049be04fc --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/kt49658Strict.txt @@ -0,0 +1,4 @@ +package + +public fun doTheMapThing1(/*0*/ elements: kotlin.collections.List): kotlin.collections.List +public fun doTheMapThing2(/*0*/ elements: kotlin.collections.List): kotlin.collections.List 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 399dfe9f974..49d83dec5fb 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 @@ -13653,6 +13653,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/kt47316.kt"); } + @Test + @TestMetadata("kt49658.kt") + public void testKt49658() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658.kt"); + } + + @Test + @TestMetadata("kt49658Strict.kt") + public void testKt49658Strict() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/kt49658Strict.kt"); + } + @Test @TestMetadata("kt6175.kt") public void testKt6175() throws Exception { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 200b083caee..fa083a975c1 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -249,6 +249,7 @@ enum class LanguageFeature( // 1.8 + DontLoseDiagnosticsDuringOverloadResolutionByReturnType(KOTLIN_1_8), ProhibitConfusingSyntaxInWhenBranches(KOTLIN_1_8, kind = BUG_FIX), // KT-48385 UseConsistentRulesForPrivateConstructorsOfSealedClasses(sinceVersion = KOTLIN_1_8, kind = BUG_FIX), // KT-44866 ProgressionsChangingResolve(KOTLIN_1_8), // KT-49276