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 7d7cc50e39e..9ac22d573d1 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -18079,6 +18079,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/regressions/kt35668.kt"); } + @TestMetadata("kt36222.kt") + public void testKt36222() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt36222.kt"); + } + @TestMetadata("kt3647.kt") public void testKt3647() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/kt3647.kt"); 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 a3047b46541..5e7f867b679 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -33,6 +33,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils +import org.jetbrains.kotlin.types.typeUtil.isNullableNothing +import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.utils.addToStdlib.cast import org.jetbrains.kotlin.utils.addToStdlib.safeAs @@ -333,12 +335,15 @@ class DiagnosticReporterByTrackingStrategy( (position as? ExpectedTypeConstraintPosition)?.let { val call = it.topLevelCall.psiKotlinCall.psiCall.callElement.safeAs() + val inferredType = + if (!constraintError.lowerKotlinType.isNullableNothing()) constraintError.lowerKotlinType + else constraintError.upperKotlinType.makeNullable() reportIfNonNull(call) { trace.report( Errors.TYPE_MISMATCH.on( it, constraintError.upperKotlinType, - constraintError.lowerKotlinType + inferredType ) ) } diff --git a/compiler/testData/diagnostics/tests/regressions/kt36222.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt36222.fir.kt new file mode 100644 index 00000000000..d7a23988aaa --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt36222.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(f: () -> String) {} +fun select(x: K, y: K): K = x + +fun test() { + foo { select("non-null", null) } // inferred String? but String is expected +} diff --git a/compiler/testData/diagnostics/tests/regressions/kt36222.kt b/compiler/testData/diagnostics/tests/regressions/kt36222.kt new file mode 100644 index 00000000000..e62d0c00d6d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt36222.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun foo(f: () -> String) {} +fun select(x: K, y: K): K = x + +fun test() { + foo { select("non-null", null) } // inferred String? but String is expected +} + diff --git a/compiler/testData/diagnostics/tests/regressions/kt36222.txt b/compiler/testData/diagnostics/tests/regressions/kt36222.txt new file mode 100644 index 00000000000..eea1c57527d --- /dev/null +++ b/compiler/testData/diagnostics/tests/regressions/kt36222.txt @@ -0,0 +1,5 @@ +package + +public fun foo(/*0*/ f: () -> kotlin.String): kotlin.Unit +public fun select(/*0*/ x: K, /*1*/ y: K): K +public fun test(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 4b971012f9c..ddddc19fe4d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -18091,6 +18091,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali runTest("compiler/testData/diagnostics/tests/regressions/kt35668.kt"); } + @TestMetadata("kt36222.kt") + public void testKt36222() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt36222.kt"); + } + @TestMetadata("kt3647.kt") public void testKt3647() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/kt3647.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 041d85739ec..b15c013594b 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -18081,6 +18081,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/regressions/kt35668.kt"); } + @TestMetadata("kt36222.kt") + public void testKt36222() throws Exception { + runTest("compiler/testData/diagnostics/tests/regressions/kt36222.kt"); + } + @TestMetadata("kt3647.kt") public void testKt3647() throws Exception { runTest("compiler/testData/diagnostics/tests/regressions/kt3647.kt");