[FIR2IR] Unwrap only call-site overrides during delegated members generation
^KT-60251 Fixed
This commit is contained in:
committed by
Space Team
parent
6dc56158f9
commit
a15057b2ca
+12
-9
@@ -121,7 +121,7 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
|
||||
?: return@processAllFunctions
|
||||
|
||||
val delegateToSymbol = findDelegateToSymbol(
|
||||
unwrapped.unwrapSubstitutionOverrides().symbol,
|
||||
unwrapped.symbol,
|
||||
delegateToScope::processFunctionsByName,
|
||||
delegateToScope::processOverriddenFunctions
|
||||
) ?: return@processAllFunctions
|
||||
@@ -145,7 +145,7 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
|
||||
?: return@processAllProperties
|
||||
|
||||
val delegateToSymbol = findDelegateToSymbol(
|
||||
unwrapped.unwrapSubstitutionOverrides().symbol,
|
||||
unwrapped.symbol,
|
||||
{ name, processor ->
|
||||
delegateToScope.processPropertiesByName(name) {
|
||||
if (it !is FirPropertySymbol) return@processPropertiesByName
|
||||
@@ -167,29 +167,32 @@ class DelegatedMemberGenerator(private val components: Fir2IrComponents) : Fir2I
|
||||
}
|
||||
|
||||
private inline fun <reified S : FirCallableSymbol<*>> findDelegateToSymbol(
|
||||
unwrappedSymbol: S,
|
||||
symbol: S,
|
||||
processCallables: (name: Name, processor: (S) -> Unit) -> Unit,
|
||||
crossinline processOverridden: (base: S, processor: (S) -> ProcessorAction) -> ProcessorAction
|
||||
): S? {
|
||||
val unwrappedSymbol = symbol.unwrapUseSiteSubstitutionOverrides()
|
||||
var result: S? = null
|
||||
// The purpose of this code is to find member in delegate-to scope
|
||||
// which matches or overrides unwrappedSymbol (which is in turn taken from subclass scope).
|
||||
processCallables(unwrappedSymbol.name) { candidateSymbol ->
|
||||
if (result != null) return@processCallables
|
||||
if (candidateSymbol === unwrappedSymbol) {
|
||||
result = candidateSymbol
|
||||
val unwrappedCandidateSymbol = candidateSymbol.unwrapUseSiteSubstitutionOverrides()
|
||||
if (unwrappedCandidateSymbol === unwrappedSymbol) {
|
||||
result = unwrappedCandidateSymbol
|
||||
return@processCallables
|
||||
}
|
||||
processOverridden(candidateSymbol) {
|
||||
if (it === unwrappedSymbol) {
|
||||
result = candidateSymbol
|
||||
processOverridden(candidateSymbol) { overriddenSymbol ->
|
||||
val unwrappedOverriddenSymbol = overriddenSymbol.unwrapUseSiteSubstitutionOverrides()
|
||||
if (unwrappedOverriddenSymbol === unwrappedSymbol) {
|
||||
result = unwrappedCandidateSymbol
|
||||
ProcessorAction.STOP
|
||||
} else {
|
||||
ProcessorAction.NEXT
|
||||
}
|
||||
}
|
||||
}
|
||||
return result?.unwrapSubstitutionOverrides()
|
||||
return result
|
||||
}
|
||||
|
||||
@OptIn(UnsafeDuringIrConstructionAPI::class)
|
||||
|
||||
@@ -146,6 +146,10 @@ inline fun <reified D : FirCallableDeclaration> D.unwrapUseSiteSubstitutionOverr
|
||||
} while (true)
|
||||
}
|
||||
|
||||
inline fun <reified S : FirCallableSymbol<*>> S.unwrapUseSiteSubstitutionOverrides(): S {
|
||||
return fir.unwrapUseSiteSubstitutionOverrides().symbol as S
|
||||
}
|
||||
|
||||
inline fun <reified S : FirCallableSymbol<*>> S.unwrapFakeOverrides(): S = fir.unwrapFakeOverrides().symbol as S
|
||||
|
||||
inline fun <reified S : FirCallableSymbol<*>> S.unwrapSubstitutionOverrides(): S = fir.unwrapSubstitutionOverrides().symbol as S
|
||||
|
||||
Vendored
+2
@@ -1,5 +1,7 @@
|
||||
// ISSUE: KT-55828
|
||||
// DUMP_IR
|
||||
// IGNORE_BACKEND_K2: ANY
|
||||
// Ignore reason: FIR scopes skip part of overridden hierarchy. It will fixed in next commits
|
||||
// IGNORE_CODEGEN_WITH_IR_FAKE_OVERRIDE_GENERATION: extra overridden symbols for declarations in MyMutableList.
|
||||
// ^ This is most likely not a problem, and IR dump can be changed once IR fake override generation is enabled by default.
|
||||
|
||||
|
||||
+11
-11
@@ -17,7 +17,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:element index:0 type:@[FlexibleNullability] kotlin.String?
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun add (element: @[FlexibleNullability] kotlin.String?): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun add (element: E of kotlin.collections.MutableSet): kotlin.Boolean declared in kotlin.collections.MutableSet' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun add (element: @[FlexibleNullability] kotlin.String?): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.add' type=<root>.Impl origin=null
|
||||
element: GET_VAR 'element: @[FlexibleNullability] kotlin.String? declared in <root>.Impl.add' type=@[FlexibleNullability] kotlin.String? origin=null
|
||||
@@ -29,7 +29,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:elements index:0 type:kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun addAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun addAll (elements: kotlin.collections.Collection<E of kotlin.collections.MutableSet>): kotlin.Boolean declared in kotlin.collections.MutableSet' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun addAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.addAll' type=<root>.Impl origin=null
|
||||
elements: GET_VAR 'elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> declared in <root>.Impl.addAll' type=kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@@ -39,7 +39,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
public abstract fun clear (): kotlin.Unit declared in <root>.Foo.B
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
|
||||
BLOCK_BODY
|
||||
CALL 'public abstract fun clear (): kotlin.Unit declared in kotlin.collections.MutableSet' type=kotlin.Unit origin=null
|
||||
CALL 'public abstract fun clear (): kotlin.Unit declared in <root>.Foo.B' type=kotlin.Unit origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.clear' type=<root>.Impl origin=null
|
||||
FUN DELEGATED_MEMBER name:iterator visibility:public modality:OPEN <> ($this:<root>.Impl) returnType:kotlin.collections.MutableIterator<@[FlexibleNullability] kotlin.String?> [operator]
|
||||
@@ -49,7 +49,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun iterator (): kotlin.collections.MutableIterator<@[FlexibleNullability] kotlin.String?> declared in <root>.Impl'
|
||||
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<E of kotlin.collections.MutableSet> declared in kotlin.collections.MutableSet' type=kotlin.collections.MutableIterator<E of kotlin.collections.MutableSet> origin=null
|
||||
CALL 'public abstract fun iterator (): kotlin.collections.MutableIterator<@[FlexibleNullability] kotlin.String?> declared in <root>.Foo.B' type=kotlin.collections.MutableIterator<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.iterator' type=<root>.Impl origin=null
|
||||
FUN DELEGATED_MEMBER name:remove visibility:public modality:OPEN <> ($this:<root>.Impl, element:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Boolean
|
||||
@@ -60,7 +60,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:element index:0 type:@[FlexibleNullability] kotlin.String?
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun remove (element: @[FlexibleNullability] kotlin.String?): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun remove (element: E of kotlin.collections.MutableSet): kotlin.Boolean declared in kotlin.collections.MutableSet' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun remove (element: @[FlexibleNullability] kotlin.String?): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.remove' type=<root>.Impl origin=null
|
||||
element: GET_VAR 'element: @[FlexibleNullability] kotlin.String? declared in <root>.Impl.remove' type=@[FlexibleNullability] kotlin.String? origin=null
|
||||
@@ -72,7 +72,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:elements index:0 type:kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun removeAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun removeAll (elements: kotlin.collections.Collection<E of kotlin.collections.MutableSet>): kotlin.Boolean declared in kotlin.collections.MutableSet' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun removeAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.removeAll' type=<root>.Impl origin=null
|
||||
elements: GET_VAR 'elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> declared in <root>.Impl.removeAll' type=kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@@ -84,7 +84,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:elements index:0 type:kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun retainAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun retainAll (elements: kotlin.collections.Collection<E of kotlin.collections.MutableSet>): kotlin.Boolean declared in kotlin.collections.MutableSet' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun retainAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.retainAll' type=<root>.Impl origin=null
|
||||
elements: GET_VAR 'elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> declared in <root>.Impl.retainAll' type=kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@@ -95,7 +95,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun isEmpty (): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun isEmpty (): kotlin.Boolean declared in kotlin.collections.Set' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun isEmpty (): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.isEmpty' type=<root>.Impl origin=null
|
||||
FUN DELEGATED_MEMBER name:contains visibility:public modality:OPEN <> ($this:<root>.Impl, element:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Boolean [operator]
|
||||
@@ -106,7 +106,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:element index:0 type:@[FlexibleNullability] kotlin.String?
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun contains (element: @[FlexibleNullability] kotlin.String?): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun contains (element: E of kotlin.collections.Set): kotlin.Boolean declared in kotlin.collections.Set' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun contains (element: @[FlexibleNullability] kotlin.String?): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.contains' type=<root>.Impl origin=null
|
||||
element: GET_VAR 'element: @[FlexibleNullability] kotlin.String? declared in <root>.Impl.contains' type=@[FlexibleNullability] kotlin.String? origin=null
|
||||
@@ -118,7 +118,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
VALUE_PARAMETER name:elements index:0 type:kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun containsAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Impl'
|
||||
CALL 'public abstract fun containsAll (elements: kotlin.collections.Collection<E of kotlin.collections.Set>): kotlin.Boolean declared in kotlin.collections.Set' type=kotlin.Boolean origin=null
|
||||
CALL 'public abstract fun containsAll (elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?>): kotlin.Boolean declared in <root>.Foo.B' type=kotlin.Boolean origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.containsAll' type=<root>.Impl origin=null
|
||||
elements: GET_VAR 'elements: kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> declared in <root>.Impl.containsAll' type=kotlin.collections.Collection<@[FlexibleNullability] kotlin.String?> origin=null
|
||||
@@ -134,7 +134,7 @@ FILE fqName:<root> fileName:/DelegationAndInheritanceFromJava.kt
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Impl
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun <get-size> (): kotlin.Int declared in <root>.Impl'
|
||||
CALL 'public abstract fun <get-size> (): kotlin.Int declared in kotlin.collections.Set' type=kotlin.Int origin=null
|
||||
CALL 'public abstract fun <get-size> (): kotlin.Int declared in <root>.Foo.B' type=kotlin.Int origin=null
|
||||
$this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:<root>.Foo.B visibility:private [final]' type=<root>.Foo.B origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Impl declared in <root>.Impl.<get-size>' type=<root>.Impl origin=null
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
|
||||
Reference in New Issue
Block a user