diff --git a/compiler/fir/analysis-tests/testData/resolve/scopes/getterOverrideAndKotlinProperty.overrides.txt b/compiler/fir/analysis-tests/testData/resolve/scopes/getterOverrideAndKotlinProperty.overrides.txt index 0c786a4cb57..9cf29e24c4a 100644 --- a/compiler/fir/analysis-tests/testData/resolve/scopes/getterOverrideAndKotlinProperty.overrides.txt +++ b/compiler/fir/analysis-tests/testData/resolve/scopes/getterOverrideAndKotlinProperty.overrides.txt @@ -7,9 +7,14 @@ B: C: [Source]: public open override fun getFoo(): R|kotlin/String| from Java enhancement scope for /C [id: 0] + [Source]: public open override fun getFoo(): R|kotlin/String| from Use site scope of /B [id: 0] + [Enhancement]: public abstract fun getFoo(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] [Enhancement]: public abstract fun getFoo(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] D: [Source]: public open override fun getFoo(): R|kotlin/String| from Use site scope of /D [id: 0] - [Enhancement]: public abstract fun getFoo(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] + [Source]: public open override fun getFoo(): R|kotlin/String| from Java enhancement scope for /C [id: 0] + [Source]: public open override fun getFoo(): R|kotlin/String| from Use site scope of /B [id: 0] + [Enhancement]: public abstract fun getFoo(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] + [Enhancement]: public abstract fun getFoo(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] diff --git a/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers.overrides.txt b/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers.overrides.txt index be866ea1148..130c86fdb69 100644 --- a/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers.overrides.txt +++ b/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers.overrides.txt @@ -1,26 +1,38 @@ C: [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /C [id: 0] [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 1] + [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /B [id: 0] + [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 1] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /C [id: 0] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 1] + [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /B [id: 0] + [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 1] Explicit: [Source]: public abstract override fun foo(): R|kotlin/Int| from Use site scope of /Explicit [id: 0] [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract fun foo(): R|kotlin/Int| from Use site scope of /D [id: 3] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /Explicit [id: 0] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /D [id: 3] Implicit: [IntersectionOverride]: public abstract fun foo(): R|kotlin/Int| from Use site scope of /Implicit [id: 0] [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract fun foo(): R|kotlin/Int| from Use site scope of /D [id: 3] [IntersectionOverride]: public abstract override val x: R|kotlin/Any| from Use site scope of /Implicit [id: 0] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /D [id: 3] diff --git a/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers_java.overrides.txt b/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers_java.overrides.txt index 5bbcbed223f..130c86fdb69 100644 --- a/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers_java.overrides.txt +++ b/compiler/fir/analysis-tests/testData/resolve/scopes/noIntersectionOverrideOfTwoMembers_java.overrides.txt @@ -1,25 +1,38 @@ C: [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /C [id: 0] [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 1] + [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /B [id: 0] + [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 1] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /C [id: 0] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 1] + [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /B [id: 0] + [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 1] Explicit: [Source]: public abstract override fun foo(): R|kotlin/Int| from Use site scope of /Explicit [id: 0] [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract fun foo(): R|kotlin/Int| from Use site scope of /D [id: 3] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /Explicit [id: 0] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /D [id: 3] Implicit: [IntersectionOverride]: public abstract fun foo(): R|kotlin/Int| from Use site scope of /Implicit [id: 0] [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override fun foo(): R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract fun foo(): R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract fun foo(): R|kotlin/Int| from Use site scope of /D [id: 3] [IntersectionOverride]: public abstract override val x: R|kotlin/Any| from Use site scope of /Implicit [id: 0] [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /C [id: 1] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] + [Source]: public abstract override val x: R|kotlin/Any| from Use site scope of /B [id: 1] + [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /A [id: 2] [Source]: public abstract val x: R|kotlin/Any| from Use site scope of /D [id: 3] + diff --git a/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt b/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt index 5efce24008f..dda4567f403 100644 --- a/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt +++ b/compiler/fir/analysis-tests/testData/resolve/scopes/publicJavaAndPrivateKotlinVar.overrides.txt @@ -1,6 +1,7 @@ C: [Source]: public open override fun getName(): R|kotlin/String| from Use site scope of /C [id: 0] [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] + [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Use site scope of /C [id: 0] [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft| from Java enhancement scope for /B [id: 2] @@ -8,10 +9,13 @@ C: D: [Source]: public open override fun getName(): R|kotlin/String| from Java enhancement scope for /D [id: 0] - [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] + [Source]: public open override fun getName(): R|kotlin/String| from Use site scope of /C [id: 0] + [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] + [Enhancement]: public abstract fun getName(): R|kotlin/String!| from Java enhancement scope for /A [id: 1] [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Java enhancement scope for /D [id: 0] - [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] - [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft| from Java enhancement scope for /B [id: 2] + [Source]: public open override fun setName(newName: R|kotlin/String|): R|kotlin/Any?| from Use site scope of /C [id: 0] + [SubstitutionOverride(DeclarationSite)]: public abstract fun setName(newName: R|kotlin/String!|): R|kotlin/Any!| from Substitution scope for [Java enhancement scope for /B] for type C [id: 1] + [Enhancement]: public abstract fun setName(newName: R|kotlin/String!|): R|ft| from Java enhancement scope for /B [id: 2] [Source]: private final var name: R|kotlin/String| from Java enhancement scope for /D [id: 0] [Source]: private final var name: R|kotlin/String| from Use site scope of /C [id: 0] diff --git a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsNameClashClassMembersChecker.kt b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsNameClashClassMembersChecker.kt index 6abd0dbed77..d8f65dd7094 100644 --- a/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsNameClashClassMembersChecker.kt +++ b/compiler/fir/checkers/checkers.js/src/org/jetbrains/kotlin/fir/analysis/js/checkers/declaration/FirJsNameClashClassMembersChecker.kt @@ -37,15 +37,16 @@ object FirJsNameClashClassMembersChecker : FirClassChecker() { private val allSymbols = mutableSetOf>() private fun FirTypeScope.collectOverriddenLeaves(classMemberSymbol: FirCallableSymbol<*>): Set> { - val visitedSymbols = hashSetOf(classMemberSymbol) - val symbolsToProcess = mutableListOf(classMemberSymbol) + val startMemberWithScope = MemberWithBaseScope(classMemberSymbol, this) + val visitedSymbols = hashSetOf(startMemberWithScope) + val symbolsToProcess = mutableListOf(startMemberWithScope) val leaves = mutableSetOf>() while (symbolsToProcess.isNotEmpty()) { - val processingSymbol = symbolsToProcess.popLast() - val overriddenMembers = getDirectOverriddenMembers(processingSymbol, true) - for (overriddenMember in overriddenMembers) { - if (visitedSymbols.add(overriddenMember)) { - symbolsToProcess.add(overriddenMember) + val (processingSymbol, scope) = symbolsToProcess.popLast() + val overriddenMembers = scope.getDirectOverriddenMembersWithBaseScope(processingSymbol) + for (overriddenMemberWithScope in overriddenMembers) { + if (visitedSymbols.add(overriddenMemberWithScope)) { + symbolsToProcess.add(overriddenMemberWithScope) } } if (overriddenMembers.isEmpty()) { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt index 49a6985bca5..9c7a9f470a6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirHelpers.kt @@ -214,7 +214,7 @@ fun CheckerContext.findClosestClassOrObject(): FirClass? { fun FirNamedFunctionSymbol.overriddenFunctions( containingClass: FirClassSymbol<*>, context: CheckerContext, -): List> { +): Collection> { return overriddenFunctions(containingClass, context.session, context.scopeSession) } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt index f9916d1b572..7cc3f3c4cf5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirNotImplementedOverrideChecker.kt @@ -64,9 +64,9 @@ object FirNotImplementedOverrideChecker : FirClassChecker() { fun collectSymbol(symbol: FirCallableSymbol<*>) { val delegatedWrapperData = symbol.delegatedWrapperData if (delegatedWrapperData != null) { - val directOverriddenMembersWithBaseScope = classScope.getDirectOverriddenMembersWithBaseScope( - symbol - ) + val directOverriddenMembersWithBaseScope = classScope + .getDirectOverriddenMembersWithBaseScope(symbol) + .filter { it.member != symbol } @Suppress("UNCHECKED_CAST") val filteredOverriddenMembers = when (symbol) { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt index c8d26f803d7..8366985b807 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/DelegatedMemberGenerator.kt @@ -46,8 +46,8 @@ import org.jetbrains.kotlin.name.Name * TODO: generic super interface types and generic delegated members. */ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2IrComponents by components { - private val baseFunctionSymbols: MutableMap> = mutableMapOf() - private val basePropertySymbols: MutableMap> = mutableMapOf() + private val baseFunctionSymbols: MutableMap> = mutableMapOf() + private val basePropertySymbols: MutableMap> = mutableMapOf() private data class DeclarationBodyInfo( val declaration: IrDeclaration, @@ -231,7 +231,7 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I delegateOverride, subClass, predefinedOrigin = IrDeclarationOrigin.DELEGATED_MEMBER, fakeOverrideOwnerLookupTag = firSubClass.symbol.toLookupTag() ) - val baseSymbols = mutableListOf() + val baseSymbols = mutableSetOf() // the overridden symbols should be collected only after all fake overrides for all superclases are created and bound to their // overridden symbols, otherwise in some cases they will be left in inconsistent state leading to the errors in IR delegateOverride.processOverriddenFunctionSymbols(firSubClass) { @@ -364,7 +364,7 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I ) // the overridden symbols should be collected only after all fake overrides for all superclases are created and bound to their // overridden symbols, otherwise in some cases they will be left in inconsistent state leading to the errors in IR - val baseSymbols = mutableListOf() + val baseSymbols = mutableSetOf() firDelegateProperty.processOverriddenPropertySymbols(firSubClass) { baseSymbols.add(it) } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt index 803ff774676..d861792754e 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/Scopes.kt @@ -61,7 +61,7 @@ fun FirNamedFunctionSymbol.overriddenFunctions( containingClass: FirClassSymbol<*>, session: FirSession, scopeSession: ScopeSession, -): List> { +): Collection> { val firTypeScope = containingClass.unsubstitutedScope( session, scopeSession, @@ -69,12 +69,20 @@ fun FirNamedFunctionSymbol.overriddenFunctions( memberRequiredPhase = FirResolvePhase.STATUS, ) - val overriddenFunctions = mutableListOf>() + val overriddenFunctions = mutableSetOf>() firTypeScope.processFunctionsByName(callableId.callableName) { } firTypeScope.processOverriddenFunctions(this) { overriddenFunctions.add(it) ProcessorAction.NEXT } + /* + * The original symbol may appear in `processOverriddenFunctions`, so it should be removed from the resulting + * list to not confuse the caller with a situation when the function directly overrides itself + * + * For details see FirTypeScope.processDirectOverriddenFunctionsWithBaseScope + */ + overriddenFunctions -= this + return overriddenFunctions } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt index e0fba8ece47..956c61000e6 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirTypeScope.kt @@ -262,6 +262,14 @@ fun FirTypeScope.getDirectOverriddenFunctions( ProcessorAction.NEXT } + /* + * The original symbol may appear in `processOverriddenFunctions`, so it should be removed from the resulting + * list to not confuse the caller with a situation when the function directly overrides itself + * + * For details see FirTypeScope.processDirectOverriddenFunctionsWithBaseScope + */ + overriddenFunctions -= function + return overriddenFunctions.toList() } @@ -276,6 +284,11 @@ fun FirTypeScope.getDirectOverriddenProperties( ProcessorAction.NEXT } + /* + * See comment in `getDirectOverriddenFunctions` function above + */ + overriddenProperties -= property + return overriddenProperties.toList() } @@ -295,7 +308,7 @@ fun FirTypeScope.retrieveDirectOverriddenOf(memberSymbol: FirCallableSymbol<*>): } } -private inline fun > MutableCollection.addOverridden( +private inline fun > MutableSet.addOverridden( symbol: D, unwrapIntersectionAndSubstitutionOverride: Boolean ) { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirUnstableSmartcastTypeScope.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirUnstableSmartcastTypeScope.kt index ae46b11cd62..af76cee8874 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirUnstableSmartcastTypeScope.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/scopes/FirUnstableSmartcastTypeScope.kt @@ -59,23 +59,29 @@ class FirUnstableSmartcastTypeScope( return processComposite(FirScope::processPropertiesByName, name, processor) } - private inline fun > processTypedComposite( - process: FirTypeScope.(N, (T, FirTypeScope) -> ProcessorAction) -> ProcessorAction, - name: N, - noinline processor: (T, FirTypeScope) -> ProcessorAction + private inline fun > processDirectOverriddenWithBaseScope( + originalSymbol: S, + processDirectOverriddenSymbolsWithBaseScope: FirTypeScope.(S, (S, FirTypeScope) -> ProcessorAction) -> ProcessorAction, + noinline processor: (S, FirTypeScope) -> ProcessorAction ): ProcessorAction { - val unique = mutableSetOf() - originalScope.process(name) { symbol, firTypeScope -> + val unique = mutableSetOf() + originalScope.processDirectOverriddenSymbolsWithBaseScope(originalSymbol) { symbol, firTypeScope -> unique += symbol processor(symbol, firTypeScope) }.let { if (it == ProcessorAction.STOP) return ProcessorAction.STOP } - smartcastScope.process(name) { symbol, firTypeScope -> - if (symbol !in unique) { - markSymbolFromUnstableSmartcast(symbol) - processor(symbol, firTypeScope) - } else { - ProcessorAction.NEXT + smartcastScope.processDirectOverriddenSymbolsWithBaseScope(originalSymbol) { symbol, firTypeScope -> + when (symbol) { + /** + * `processDirectOverriddenSymbolsWithBaseScope` may return the same symbol from underlying scopes, + * so we need to skip them until we found real overridden + */ + originalSymbol -> ProcessorAction.NEXT + !in unique -> { + markSymbolFromUnstableSmartcast(symbol) + processor(symbol, firTypeScope) + } + else -> ProcessorAction.NEXT } }.let { if (it == ProcessorAction.STOP) return ProcessorAction.STOP } return ProcessorAction.NEXT @@ -91,14 +97,14 @@ class FirUnstableSmartcastTypeScope( functionSymbol: FirNamedFunctionSymbol, processor: (FirNamedFunctionSymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction { - return processTypedComposite(FirTypeScope::processDirectOverriddenFunctionsWithBaseScope, functionSymbol, processor) + return processDirectOverriddenWithBaseScope(functionSymbol, FirTypeScope::processDirectOverriddenFunctionsWithBaseScope, processor) } override fun processDirectOverriddenPropertiesWithBaseScope( propertySymbol: FirPropertySymbol, processor: (FirPropertySymbol, FirTypeScope) -> ProcessorAction ): ProcessorAction { - return processTypedComposite(FirTypeScope::processDirectOverriddenPropertiesWithBaseScope, propertySymbol, processor) + return processDirectOverriddenWithBaseScope(propertySymbol, FirTypeScope::processDirectOverriddenPropertiesWithBaseScope, processor) } override fun getCallableNames(): Set { diff --git a/compiler/testData/codegen/bytecodeText/falseSmartCast.kt b/compiler/testData/codegen/bytecodeText/falseSmartCast.kt index 8f4a85968ed..a839cfa3870 100644 --- a/compiler/testData/codegen/bytecodeText/falseSmartCast.kt +++ b/compiler/testData/codegen/bytecodeText/falseSmartCast.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_K2: JVM_IR open class SuperFoo { public fun bar() { if (this is Foo) { @@ -13,4 +12,4 @@ class Foo : SuperFoo() // 1 INVOKEVIRTUAL SuperFoo.baz // 0 CHECKCAST Foo -// 0 INVOKEVIRTUAL Foo.baz \ No newline at end of file +// 0 INVOKEVIRTUAL Foo.baz diff --git a/compiler/testData/ir/irText/classes/smartCastInValInitialization.fir.ir.txt b/compiler/testData/ir/irText/classes/smartCastInValInitialization.fir.ir.txt deleted file mode 100644 index cf7f3a9cf7d..00000000000 --- a/compiler/testData/ir/irText/classes/smartCastInValInitialization.fir.ir.txt +++ /dev/null @@ -1,65 +0,0 @@ -FILE fqName: fileName:/smartCastInValInitialization.kt - CLASS CLASS name:RootBus modality:FINAL visibility:public superTypes:[.MessageBusImpl] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.RootBus - CONSTRUCTOR visibility:public <> () returnType:.RootBus [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in .MessageBusImpl' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:RootBus modality:FINAL visibility:public superTypes:[.MessageBusImpl]' - PROPERTY FAKE_OVERRIDE name:parentBus visibility:public modality:FINAL [fake_override,val] - overridden: - public final parentBus: kotlin.Any? - FUN FAKE_OVERRIDE name: visibility:public modality:FINAL <> ($this:.MessageBusImpl) returnType:kotlin.Any? [fake_override] - correspondingProperty: PROPERTY FAKE_OVERRIDE name:parentBus visibility:public modality:FINAL [fake_override,val] - overridden: - public final fun (): kotlin.Any? declared in .MessageBusImpl - $this: VALUE_PARAMETER name: type:.MessageBusImpl - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .MessageBusImpl - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in .MessageBusImpl - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in .MessageBusImpl - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS CLASS name:MessageBusImpl modality:OPEN visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.MessageBusImpl - CONSTRUCTOR visibility:public <> () returnType:.MessageBusImpl [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:MessageBusImpl modality:OPEN visibility:public superTypes:[kotlin.Any]' - PROPERTY name:parentBus visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:parentBus type:kotlin.Any? visibility:private [final] - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.MessageBusImpl) returnType:kotlin.Any? - correspondingProperty: PROPERTY name:parentBus visibility:public modality:FINAL [val] - $this: VALUE_PARAMETER name: type:.MessageBusImpl - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.Any? declared in .MessageBusImpl' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:parentBus type:kotlin.Any? visibility:private [final]' type=kotlin.Any? origin=null - receiver: GET_VAR ': .MessageBusImpl declared in .MessageBusImpl.' type=.MessageBusImpl origin=null - ANONYMOUS_INITIALIZER isStatic=false - BLOCK_BODY - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - TYPE_OP type=.RootBus origin=CAST typeOperand=.RootBus - GET_VAR ': .MessageBusImpl declared in .MessageBusImpl' type=.MessageBusImpl origin=null - SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:parentBus type:kotlin.Any? visibility:private [final]' type=kotlin.Unit origin=null - receiver: TYPE_OP type=.RootBus origin=IMPLICIT_CAST typeOperand=.RootBus - GET_VAR ': .MessageBusImpl declared in .MessageBusImpl' type=.MessageBusImpl origin=null - value: CONST Null type=kotlin.Nothing? value=null - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/classes/smartCastInValInitialization.fir.kt.txt b/compiler/testData/ir/irText/classes/smartCastInValInitialization.fir.kt.txt deleted file mode 100644 index f2c17e59e3c..00000000000 --- a/compiler/testData/ir/irText/classes/smartCastInValInitialization.fir.kt.txt +++ /dev/null @@ -1,25 +0,0 @@ -class RootBus : MessageBusImpl { - constructor() /* primary */ { - super/*MessageBusImpl*/() - /* () */ - - } - -} - -open class MessageBusImpl { - constructor() /* primary */ { - super/*Any*/() - /* () */ - - } - - val parentBus: Any? - get - - init { - as RootBus /*~> Unit */ - /*as RootBus */.#parentBus = null - } - -} diff --git a/compiler/testData/ir/irText/classes/smartCastInValInitialization.kt b/compiler/testData/ir/irText/classes/smartCastInValInitialization.kt index 39cec492f95..d7aa58fe018 100644 --- a/compiler/testData/ir/irText/classes/smartCastInValInitialization.kt +++ b/compiler/testData/ir/irText/classes/smartCastInValInitialization.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class RootBus: MessageBusImpl() open class MessageBusImpl { diff --git a/compiler/testData/ir/irText/expressions/smartCastAside.fir.ir.txt b/compiler/testData/ir/irText/expressions/smartCastAside.fir.ir.txt deleted file mode 100644 index 39db290b85a..00000000000 --- a/compiler/testData/ir/irText/expressions/smartCastAside.fir.ir.txt +++ /dev/null @@ -1,76 +0,0 @@ -FILE fqName: fileName:/smartCastAside.kt - CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A - FUN name:foo visibility:public modality:ABSTRACT <> ($this:.A) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.A - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS INTERFACE name:B modality:ABSTRACT visibility:public superTypes:[.A] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B - FUN name:bar visibility:public modality:ABSTRACT <> ($this:.B) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.B - FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:.A) returnType:kotlin.Unit [fake_override] - overridden: - public abstract fun foo (): kotlin.Unit declared in .A - $this: VALUE_PARAMETER name: type:.A - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .A - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in .A - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in .A - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS INTERFACE name:C modality:ABSTRACT visibility:public superTypes:[.A] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C - FUN name:baz visibility:public modality:ABSTRACT <> ($this:.C) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.C - FUN FAKE_OVERRIDE name:foo visibility:public modality:ABSTRACT <> ($this:.A) returnType:kotlin.Unit [fake_override] - overridden: - public abstract fun foo (): kotlin.Unit declared in .A - $this: VALUE_PARAMETER name: type:.A - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in .A - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in .A - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in .A - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:test visibility:public modality:FINAL <> (param:.B) returnType:kotlin.Unit - VALUE_PARAMETER name:param index:0 type:.B - BLOCK_BODY - WHEN type=kotlin.Unit origin=IF - BRANCH - if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.C - GET_VAR 'param: .B declared in .test' type=.B origin=null - then: BLOCK type=kotlin.Unit origin=null - CALL 'public abstract fun foo (): kotlin.Unit declared in .A' type=kotlin.Unit origin=null - $this: TYPE_OP type=.C origin=IMPLICIT_CAST typeOperand=.C - GET_VAR 'param: .B declared in .test' type=.B origin=null - CALL 'public abstract fun bar (): kotlin.Unit declared in .B' type=kotlin.Unit origin=null - $this: GET_VAR 'param: .B declared in .test' type=.B origin=null - CALL 'public abstract fun baz (): kotlin.Unit declared in .C' type=kotlin.Unit origin=null - $this: TYPE_OP type=.C origin=IMPLICIT_CAST typeOperand=.C - GET_VAR 'param: .B declared in .test' type=.B origin=null diff --git a/compiler/testData/ir/irText/expressions/smartCastAside.fir.kt.txt b/compiler/testData/ir/irText/expressions/smartCastAside.fir.kt.txt deleted file mode 100644 index 3e54b52217c..00000000000 --- a/compiler/testData/ir/irText/expressions/smartCastAside.fir.kt.txt +++ /dev/null @@ -1,24 +0,0 @@ -interface A { - abstract fun foo() - -} - -interface B : A { - abstract fun bar() - -} - -interface C : A { - abstract fun baz() - -} - -fun test(param: B) { - when { - param is C -> { // BLOCK - param /*as C */.foo() - param.bar() - param /*as C */.baz() - } - } -} diff --git a/compiler/testData/ir/irText/expressions/smartCastAside.kt b/compiler/testData/ir/irText/expressions/smartCastAside.kt index d391ec9b370..8c51584fbd7 100644 --- a/compiler/testData/ir/irText/expressions/smartCastAside.kt +++ b/compiler/testData/ir/irText/expressions/smartCastAside.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface A { fun foo() }