diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt index 6be033fddea..ce96102d769 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/types/ConeTypeContext.kt @@ -127,20 +127,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty override fun SimpleTypeMarker.withNullability(nullable: Boolean): SimpleTypeMarker { require(this is ConeKotlinType) - if (nullability.isNullable == nullable) return this - return when (this) { - is ConeCapturedType -> ConeCapturedType(captureStatus, lowerType, ConeNullability.create(nullable), constructor) - is ConeTypeParameterType -> ConeTypeParameterTypeImpl(lookupTag, nullable) - is ConeClassErrorType -> this - is ConeClassType -> ConeClassTypeImpl(lookupTag, typeArguments, nullable) - is ConeAbbreviatedType -> ConeAbbreviatedTypeImpl( - lookupTag, - typeArguments, - nullable - ) - is ConeIntersectionType -> this.withNullability(ConeNullability.create(nullable)) - else -> error("!") - } + return withNullability(ConeNullability.create(nullable)) } override fun SimpleTypeMarker.typeConstructor(): TypeConstructorMarker { diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.kt b/compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.kt new file mode 100644 index 00000000000..8d4f99ccd3a --- /dev/null +++ b/compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.kt @@ -0,0 +1,21 @@ +// FILE: BindingContext.java +public interface BindingContext { + @org.jetbrains.annotations.Nullable + V get(ReadOnlySlice slice, K key); +} + +// FILE: ReadOnlySlice.java +public interface ReadOnlySlice {} + +// FILE: Slices.java + +public class Slices { + public static ReadOnlySlice X = null; + public static ReadOnlySlice Y = null; +} + +// FILE: main.kt + +fun bar(bindingContext: BindingContext) { + bindingContext[Slices.X, bindingContext[Slices.Y, 1]] +} diff --git a/compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.txt b/compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.txt new file mode 100644 index 00000000000..66ee2e62e45 --- /dev/null +++ b/compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.txt @@ -0,0 +1,4 @@ +FILE: main.kt + public final fun bar(bindingContext: R|BindingContext|): R|kotlin/Unit| { + R|/bindingContext|.R|/BindingContext.get|!|, R|ft!|>(Q|Slices|.R|/Slices.X|, R|/bindingContext|.R|/BindingContext.get|!|, R|ft!|>(Q|Slices|.R|/Slices.Y|, Int(1))) + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 21ba746e28e..cac777cc9d5 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -41,6 +41,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/fir/resolve/testData/diagnostics/j+k"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("complexFlexibleInference.kt") + public void testComplexFlexibleInference() throws Exception { + runTest("compiler/fir/resolve/testData/diagnostics/j+k/complexFlexibleInference.kt"); + } + @TestMetadata("KJKComplexHierarchy.kt") public void testKJKComplexHierarchy() throws Exception { runTest("compiler/fir/resolve/testData/diagnostics/j+k/KJKComplexHierarchy.kt");