diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt index d8653380eb4..c33df344857 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ScopeUtils.kt @@ -12,7 +12,10 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap import org.jetbrains.kotlin.fir.scopes.FirScope -import org.jetbrains.kotlin.fir.scopes.impl.* +import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope +import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerLiteralTypeScope +import org.jetbrains.kotlin.fir.scopes.impl.FirStandardOverrideChecker +import org.jetbrains.kotlin.fir.scopes.impl.FirSuperTypeScope import org.jetbrains.kotlin.fir.scopes.scope import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl @@ -43,7 +46,9 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession) } is ConeRawType -> lowerBound.scope(useSiteSession, scopeSession) is ConeFlexibleType -> lowerBound.scope(useSiteSession, scopeSession) - is ConeIntersectionType -> FirCompositeScope( + is ConeIntersectionType -> FirSuperTypeScope.prepareSupertypeScope( + useSiteSession, + FirStandardOverrideChecker(useSiteSession), intersectedTypes.mapNotNullTo(mutableListOf()) { it.scope(useSiteSession, scopeSession) } diff --git a/compiler/fir/resolve/testData/resolve/intersectionScope.kt b/compiler/fir/resolve/testData/resolve/intersectionScope.kt new file mode 100644 index 00000000000..d7ac6acb058 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/intersectionScope.kt @@ -0,0 +1,14 @@ +interface A { + fun foo() +} + +abstract class B : A { + override fun foo() {} +} + +interface C : A {} + +fun main(c: C) { + if (c !is B) return + c.foo() +} diff --git a/compiler/fir/resolve/testData/resolve/intersectionScope.txt b/compiler/fir/resolve/testData/resolve/intersectionScope.txt new file mode 100644 index 00000000000..103a8902988 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/intersectionScope.txt @@ -0,0 +1,25 @@ +FILE: intersectionScope.kt + public abstract interface A : R|kotlin/Any| { + public abstract fun foo(): R|kotlin/Unit| + + } + public abstract class B : R|A| { + public constructor(): R|B| { + super() + } + + public open override fun foo(): R|kotlin/Unit| { + } + + } + public abstract interface C : R|A| { + } + public final fun main(c: R|C|): R|kotlin/Unit| { + when () { + (R|/c| !is R|B|) -> { + ^main Unit + } + } + + R|/c|.R|/B.foo|() + } 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 3b43bab9549..4103a7db1f1 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -143,6 +143,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/genericFunctions.kt"); } + @TestMetadata("intersectionScope.kt") + public void testIntersectionScope() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/intersectionScope.kt"); + } + @TestMetadata("intersectionTypes.kt") public void testIntersectionTypes() throws Exception { runTest("compiler/fir/resolve/testData/resolve/intersectionTypes.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 1f56633ba5e..257389e7725 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -143,6 +143,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/genericFunctions.kt"); } + @TestMetadata("intersectionScope.kt") + public void testIntersectionScope() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/intersectionScope.kt"); + } + @TestMetadata("intersectionTypes.kt") public void testIntersectionTypes() throws Exception { runTest("compiler/fir/resolve/testData/resolve/intersectionTypes.kt"); diff --git a/compiler/testData/codegen/box/increment/postfixIncrementOnShortSmartCast.kt b/compiler/testData/codegen/box/increment/postfixIncrementOnShortSmartCast.kt index e5250c40933..0dec61d0503 100644 --- a/compiler/testData/codegen/box/increment/postfixIncrementOnShortSmartCast.kt +++ b/compiler/testData/codegen/box/increment/postfixIncrementOnShortSmartCast.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR public fun box() : String { var i : Short? i = 10 diff --git a/compiler/testData/diagnostics/tests/IncDec.fir.kt b/compiler/testData/diagnostics/tests/IncDec.fir.kt index ae2a20e8b72..aae0f0cc705 100644 --- a/compiler/testData/diagnostics/tests/IncDec.fir.kt +++ b/compiler/testData/diagnostics/tests/IncDec.fir.kt @@ -23,9 +23,9 @@ class WrongIncDec() { fun testWrongIncDec() { var x = WrongIncDec() x++ - ++x + ++x x-- - --x + --x } class UnitIncDec() { @@ -43,4 +43,4 @@ fun testUnitIncDec() { x = x-- x = ++x x = --x -} \ No newline at end of file +} diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt index bd99e969b39..4ce01aefecd 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/smartcasts/SmartcastAmbiguitites.fir.kt @@ -10,7 +10,7 @@ class C() { fun test(a : Any?) { if (a is B) { if (a is C) { - a.bar(); + a.bar(); } } } diff --git a/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt b/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt index ba669aa51d4..f829414ef7f 100644 --- a/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/nullability/smartCasts.fir.kt @@ -27,8 +27,8 @@ fun foo(x: T) { x.length if (x is String) { - x.length - x?.length + x.length + x?.length x.bar1() x.bar2() diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt index de9a558ecd3..14093a54c25 100644 --- a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/classGenericsInReturnType.fir.kt @@ -31,6 +31,6 @@ import p.* fun test(b: B?) { if (b is C) { - b?.foo() + b?.foo() } } diff --git a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt index 4076dbb3560..ce16a4e7867 100644 --- a/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt +++ b/compiler/testData/diagnostics/tests/multimodule/duplicateMethod/simpleWithInheritance.fir.kt @@ -33,6 +33,6 @@ import p.* fun test(b: B?) { if (b is C && b is D) { - b?.getParent() + b?.getParent() } } diff --git a/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt b/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt index 67a60bb81f7..9884f34c1a1 100644 --- a/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt +++ b/compiler/testData/diagnostics/tests/operatorsOverloading/assignmentOperationsCheckReturnType.fir.kt @@ -4,31 +4,31 @@ fun intBinEq() { x += 1.toByte() x += 1.toShort() x += 1L - x += 1f - x += 1.0 + x += 1f + x += 1.0 x *= 'a' - x *= 1.toByte() - x *= 1.toShort() - x *= 1L - x *= 1f - x *= 1.0 + x *= 1.toByte() + x *= 1.toShort() + x *= 1L + x *= 1f + x *= 1.0 } fun shortBinEq() { var x = 0.toShort() x += 'a' x += 1.toByte() - x += 1.toShort() - x += 1L - x += 1f - x += 1.0 + x += 1.toShort() + x += 1L + x += 1f + x += 1.0 x *= 'a' - x *= 1.toByte() - x *= 1.toShort() - x *= 1L - x *= 1f - x *= 1.0 + x *= 1.toByte() + x *= 1.toShort() + x *= 1L + x *= 1f + x *= 1.0 } class A { diff --git a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt index 7ee4ad14d0d..e272ad4a854 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/genericVarianceViolation/simple.fir.kt @@ -37,7 +37,7 @@ fun main( a.foo(it) // Iterators - a.foo(ml.iterator()) + a.foo(ml.iterator()) a.foo(l.iterator()) // Sets diff --git a/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt index 4c9858a1322..a440a439747 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt9682.fir.kt @@ -15,7 +15,7 @@ interface IFoo { fun test() { val foo : Foo = Foo2() foo as IFoo - foo.bar() // Should be resolved to Foo#bar + foo.bar() // Should be resolved to Foo#bar } interface IFoo2 { @@ -24,5 +24,5 @@ interface IFoo2 { fun test2(foo: Foo) { foo as IFoo2 - foo.bar() // should be ambiguity -} \ No newline at end of file + foo.bar() // should be ambiguity +} diff --git a/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt b/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt index 8e128007ae8..6038fa4c60c 100644 --- a/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/stopResolutionOnAmbiguity.fir.kt @@ -12,7 +12,7 @@ class C() { fun test(a : Any?) { if (a is B) { if (a is C) { - a.bar(); + a.bar(); } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt index a833621f989..400cd22c3d2 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictTypeParameters.fir.kt @@ -8,6 +8,6 @@ interface B { fun test(c: Any) { if (c is B && c is A) { - c.foo() + c.foo() } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt index 3c5dc3b8e9c..4937862b11b 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/conflictingReturnType.fir.kt @@ -10,6 +10,6 @@ interface B { fun test(c: Any) { if (c is B && c is A) { - c.foo() + c.foo() } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt index d44c1402af0..d39c76a1bd0 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/flexibleTypes.fir.kt @@ -17,37 +17,37 @@ interface C { fun foo(x: Any?) { if (x is A && x is B) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } if (x is B && x is A) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } if (x is A && x is C) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } if (x is C && x is A) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } if (x is A && x is B && x is C) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } if (x is B && x is A && x is C) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } if (x is B && x is C && x is A) { - x.foo().checkType { _() } - x.foo().checkType { _() } + x.foo().checkType { _() } + x.foo().checkType { _() } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt index 3563574ea66..2020f383288 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecific.fir.kt @@ -14,6 +14,6 @@ interface B : Common { fun test(c: Common) { if (c is B && c is A) { - c.foo().checkType { _() } + c.foo().checkType { _() } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt index 3b35a6c40c9..4fea90289e3 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/mostSpecificIrrelevant.fir.kt @@ -10,6 +10,6 @@ interface B { fun test(c: Any) { if (c is B && c is A) { - c.foo().checkType { _() } + c.foo().checkType { _() } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt index 30a57852fbc..49a679504c8 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/properties.fir.kt @@ -13,9 +13,9 @@ interface B: A { fun test(a: A) { if (a is B && a is C) { - a.foo = "" - a.foo = null + a.foo = "" + a.foo = null - a.foo.checkType { _() } + a.foo.checkType { _() } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt index d899c00e3c8..7cbc3cf3c56 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/propertiesConflict.fir.kt @@ -13,8 +13,8 @@ interface B: A { fun test(a: A) { if (a is B && a is C) { - a.foo = "" - a.foo = null - a.foo + a.foo = "" + a.foo = null + a.foo } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt index c2a22a07fa2..9ebd05446bc 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/unstableSmartCast.fir.kt @@ -28,11 +28,11 @@ fun test() { x.foo().checkType { _() } if (x is B && x is C) { - x.foo().checkType { _() } + x.foo().checkType { _() } x.baz("") - x.baz(1).checkType { _() } - x.baz(1, 2) + x.baz(1).checkType { _() } + x.baz(1, 2) - x.foobar().checkType { _() } + x.foobar().checkType { _() } } } diff --git a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt index 300e51b8910..e4b40f3a43c 100644 --- a/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt +++ b/compiler/testData/diagnostics/tests/smartCasts/intersectionScope/validTypeParameters.fir.kt @@ -10,6 +10,6 @@ interface B { fun test(c: Any) { if (c is B && c is A) { - c.foo().checkType { _() } + c.foo().checkType { _() } } }