diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.fir.txt new file mode 100644 index 00000000000..5ab9c4b7c37 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.fir.txt @@ -0,0 +1,19 @@ +FILE: use.kt + public final class BeforeRunTask : R|kotlin/Any| { + public constructor(): R|BeforeRunTask| { + super() + } + + } + public abstract interface PersistentStateComponent : R|kotlin/Any| { + } + public final fun deserializeAndLoadState(component: R|PersistentStateComponent|, clazz: R|java/lang/Class| = Q|ComponentSerializationUtil|.R|/ComponentSerializationUtil.getStateClass||>((R|/component|).R|kotlin/jvm/java|)|>)): R|kotlin/Unit| { + } + public final fun use(beforeRunTask: R|BeforeRunTask<*>|): R|kotlin/Unit| { + when () { + (R|/beforeRunTask| is R|PersistentStateComponent<*>|) -> { + R|/deserializeAndLoadState|(R|/beforeRunTask|) + } + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt new file mode 100644 index 00000000000..8a0c2e382ad --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt @@ -0,0 +1,27 @@ +// FILE: ComponentSerializationUtil.java + +import org.jetbrains.annotations.NotNull; + +public final class ComponentSerializationUtil { + @NotNull + public static Class getStateClass(@NotNull Class aClass) + {} +} + +// FILE: use.kt + +class BeforeRunTask + +interface PersistentStateComponent + +fun deserializeAndLoadState( + component: PersistentStateComponent, + clazz: Class = ComponentSerializationUtil.getStateClass(component::class.java) +) {} + +fun use(beforeRunTask: BeforeRunTask<*>) { + if (beforeRunTask is PersistentStateComponent<*>) { + deserializeAndLoadState(beforeRunTask) + } +} + diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index b985c17715e..548741234b6 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -5051,6 +5051,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/IntersectionWithJavaString.kt"); } + @Test + @TestMetadata("PersistentStateComponent.kt") + public void testPersistentStateComponent() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt"); + } + @Test @TestMetadata("UastPatterns.kt") public void testUastPatterns() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index c4f0faed261..b8fe06e5496 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -5051,6 +5051,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/IntersectionWithJavaString.kt"); } + @Test + @TestMetadata("PersistentStateComponent.kt") + public void testPersistentStateComponent() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt"); + } + @Test @TestMetadata("UastPatterns.kt") public void testUastPatterns() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index 4792cdbddf0..64a0054e06e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -318,6 +318,15 @@ private fun Candidate.captureTypeFromExpressionOrNull(argumentType: ConeKotlinTy return captureTypeFromExpressionOrNull(argumentType.lowerBound, context) } + if (argumentType is ConeIntersectionType) { + val intersectedTypes = argumentType.intersectedTypes.map { captureTypeFromExpressionOrNull(it, context) ?: it } + if (intersectedTypes == argumentType.intersectedTypes) return null + return ConeIntersectionType( + intersectedTypes, + argumentType.alternativeType?.let { captureTypeFromExpressionOrNull(it, context) ?: it } + ) + } + if (argumentType !is ConeClassLikeType) return null argumentType.fullyExpandedType(context.session).let { diff --git a/compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.fir.kt b/compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.fir.kt index 0fc3c7ddd57..c81d8df0e5d 100644 --- a/compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/tooEagerSmartcast.fir.kt @@ -20,7 +20,7 @@ fun InvBase.myLastInv(): X = TODO() fun fooInv(x: InvBase) { if (x is InvDerived<*>) { - val l: T = x.myLastInv() // required T, found Cap(*). Only in NI + val l: T = x.myLastInv() // required T, found Cap(*). Only in NI } } @@ -36,7 +36,7 @@ fun Number.num() {} fun main(b: Base) { b.foo().num() if (b is Derived<*>) { - b.foo().num() - b.baz().length + b.foo().num() + b.baz().length } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/11.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/11.fir.kt index 22a2bf323b7..f65bd14affc 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/11.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/11.fir.kt @@ -52,32 +52,32 @@ fun case_3(a: Int?, b: Float?, c: Double?, d: Boolean?) { false -> b null -> c }.apply { - ?")!>this + ?")!>this if (this != null) { - ? & kotlin.Number & kotlin.Comparable<*>")!>this - ? & kotlin.Number & kotlin.Comparable<*>")!>this.equals(null) - ? & kotlin.Number & kotlin.Comparable<*>")!>this.propT - ? & kotlin.Number & kotlin.Comparable<*>")!>this.propAny - ? & kotlin.Number & kotlin.Comparable<*>")!>this.propNullableT - ? & kotlin.Number & kotlin.Comparable<*>")!>this.propNullableAny - ? & kotlin.Number & kotlin.Comparable<*>")!>this.funT() - ? & kotlin.Number & kotlin.Comparable<*>")!>this.funAny() - ? & kotlin.Number & kotlin.Comparable<*>")!>this.funNullableT() - ? & kotlin.Number & kotlin.Comparable<*>")!>this.funNullableAny() + ? & kotlin.Number & kotlin.Comparable")!>this + ? & kotlin.Number & kotlin.Comparable")!>this.equals(null) + ? & kotlin.Number & kotlin.Comparable")!>this.propT + ? & kotlin.Number & kotlin.Comparable")!>this.propAny + ? & kotlin.Number & kotlin.Comparable")!>this.propNullableT + ? & kotlin.Number & kotlin.Comparable")!>this.propNullableAny + ? & kotlin.Number & kotlin.Comparable")!>this.funT() + ? & kotlin.Number & kotlin.Comparable")!>this.funAny() + ? & kotlin.Number & kotlin.Comparable")!>this.funNullableT() + ? & kotlin.Number & kotlin.Comparable")!>this.funNullableAny() } }.let { - ?")!>it + ?")!>it if (it != null) { - ? & kotlin.Number & kotlin.Comparable<*>")!>it - ? & kotlin.Number & kotlin.Comparable<*>")!>it.equals(null) - ? & kotlin.Number & kotlin.Comparable<*>")!>it.propT - ? & kotlin.Number & kotlin.Comparable<*>")!>it.propAny - ? & kotlin.Number & kotlin.Comparable<*>")!>it.propNullableT - ? & kotlin.Number & kotlin.Comparable<*>")!>it.propNullableAny - ? & kotlin.Number & kotlin.Comparable<*>")!>it.funT() - ? & kotlin.Number & kotlin.Comparable<*>")!>it.funAny() - ? & kotlin.Number & kotlin.Comparable<*>")!>it.funNullableT() - ? & kotlin.Number & kotlin.Comparable<*>")!>it.funNullableAny() + ? & kotlin.Number & kotlin.Comparable")!>it + ? & kotlin.Number & kotlin.Comparable")!>it.equals(null) + ? & kotlin.Number & kotlin.Comparable")!>it.propT + ? & kotlin.Number & kotlin.Comparable")!>it.propAny + ? & kotlin.Number & kotlin.Comparable")!>it.propNullableT + ? & kotlin.Number & kotlin.Comparable")!>it.propNullableAny + ? & kotlin.Number & kotlin.Comparable")!>it.funT() + ? & kotlin.Number & kotlin.Comparable")!>it.funAny() + ? & kotlin.Number & kotlin.Comparable")!>it.funNullableT() + ? & kotlin.Number & kotlin.Comparable")!>it.funNullableAny() } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt index 4485b16169c..ca662a0f54a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/38.fir.kt @@ -45,7 +45,7 @@ fun case_4(x: ClassWithSixTypeParameters<*, *, *, *, *, *>?) { x.y x.z x.u - & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x!!.ip2test() + & ClassWithSixTypeParameters<*, kotlin.Nothing, *, *, kotlin.Nothing, *>")!>x!!.ip2test() ? & InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x ? & InterfaceWithTwoTypeParameters<*, *> & ClassWithSixTypeParameters<*, *, *, *, *, *>")!>x.x } diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 0a1ea3d0793..f22e79c1ba0 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -5051,6 +5051,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/IntersectionWithJavaString.kt"); } + @Test + @TestMetadata("PersistentStateComponent.kt") + public void testPersistentStateComponent() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/PersistentStateComponent.kt"); + } + @Test @TestMetadata("UastPatterns.kt") public void testUastPatterns() throws Exception {