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 e8e6cdb3926..37ae9db0d90 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java @@ -10841,6 +10841,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte runTest("compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingAndSmartCast.kt"); } + @TestMetadata("discriminatedNothingInsideComplexNestedCall.kt") + public void testDiscriminatedNothingInsideComplexNestedCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.kt"); + } + @TestMetadata("generateConstraintWithInnerNothingType.kt") public void testGenerateConstraintWithInnerNothingType() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.kt"); diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt index a00f5e5e491..94fce42ad1b 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/inference/components/ConstraintInjector.kt @@ -82,7 +82,9 @@ class ConstraintInjector( // it is important, that we add constraint here(not inside TypeCheckerContext), because inside incorporation we read constraints constraints.addConstraint(constraint)?.let { - constraintIncorporator.incorporate(typeCheckerContext, typeVariable, it) + if (!constraint.isNullabilityConstraint) { + constraintIncorporator.incorporate(typeCheckerContext, typeVariable, it) + } } } } diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.fir.kt b/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.fir.kt new file mode 100644 index 00000000000..61fdb79ced5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.fir.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun expanded(maxCapacity: Int, newCapacity: Int, buffer: Array) { + select(buffer.copyOf(newCapacity), toArray(arrayOfNulls(newCapacity))) +} + +fun select(x: K, y: K): K = x + +fun Array.copyOf(newSize: Int): Array = TODO() +inline fun arrayOfNulls(size: Int): Array = TODO() +fun toArray(array: Array): Array = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.kt b/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.kt new file mode 100644 index 00000000000..61fdb79ced5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +NewInference +// !DIAGNOSTICS: -UNUSED_PARAMETER + +fun expanded(maxCapacity: Int, newCapacity: Int, buffer: Array) { + select(buffer.copyOf(newCapacity), toArray(arrayOfNulls(newCapacity))) +} + +fun select(x: K, y: K): K = x + +fun Array.copyOf(newSize: Int): Array = TODO() +inline fun arrayOfNulls(size: Int): Array = TODO() +fun toArray(array: Array): Array = TODO() diff --git a/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.txt b/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.txt new file mode 100644 index 00000000000..832b5f77deb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.txt @@ -0,0 +1,7 @@ +package + +public inline fun arrayOfNulls(/*0*/ size: kotlin.Int): kotlin.Array +public fun expanded(/*0*/ maxCapacity: kotlin.Int, /*1*/ newCapacity: kotlin.Int, /*2*/ buffer: kotlin.Array): kotlin.Unit +public fun select(/*0*/ x: K, /*1*/ y: K): K +public fun toArray(/*0*/ array: kotlin.Array): kotlin.Array +public fun kotlin.Array.copyOf(/*0*/ newSize: kotlin.Int): kotlin.Array diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 1f6f301b3b3..b0b81811d7e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10848,6 +10848,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingAndSmartCast.kt"); } + @TestMetadata("discriminatedNothingInsideComplexNestedCall.kt") + public void testDiscriminatedNothingInsideComplexNestedCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.kt"); + } + @TestMetadata("generateConstraintWithInnerNothingType.kt") public void testGenerateConstraintWithInnerNothingType() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index 116b2394edd..11b97782305 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10843,6 +10843,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingAndSmartCast.kt"); } + @TestMetadata("discriminatedNothingInsideComplexNestedCall.kt") + public void testDiscriminatedNothingInsideComplexNestedCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/nothingType/discriminatedNothingInsideComplexNestedCall.kt"); + } + @TestMetadata("generateConstraintWithInnerNothingType.kt") public void testGenerateConstraintWithInnerNothingType() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/nothingType/generateConstraintWithInnerNothingType.kt");