diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt index 6d4ede7db35..96af01e1ade 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirDelegatedMemberScope.kt @@ -54,7 +54,7 @@ class FirDelegatedMemberScope( private fun buildScope(delegateField: FirField): FirTypeScope? = delegateField.symbol.resolvedReturnType.scope( session, scopeSession, - FakeOverrideTypeCalculator.DoNothing, + FakeOverrideTypeCalculator.Forced, requiredMembersPhase = null, ) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt index 86ffe8d2a50..413a7261bf9 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirScopeWithFakeOverrideTypeCalculator.kt @@ -6,8 +6,8 @@ package org.jetbrains.kotlin.fir.scopes.impl import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration -import org.jetbrains.kotlin.fir.isIntersectionOverride -import org.jetbrains.kotlin.fir.isSubstitutionOverride +import org.jetbrains.kotlin.fir.isDelegated +import org.jetbrains.kotlin.fir.isSubstitutionOrIntersectionOverride import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator import org.jetbrains.kotlin.fir.scopes.FirDelegatingTypeScope import org.jetbrains.kotlin.fir.scopes.FirTypeScope @@ -54,7 +54,7 @@ class FirScopeWithFakeOverrideTypeCalculator( } private fun updateReturnType(declaration: FirCallableDeclaration) { - if (declaration.isSubstitutionOverride || declaration.isIntersectionOverride) { + if (declaration.isSubstitutionOrIntersectionOverride || declaration.isDelegated) { fakeOverrideTypeCalculator.computeReturnType(declaration) } } diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt index 8f3bb3fb542..b6f2eae9f1b 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/ClassMembers.kt @@ -69,6 +69,7 @@ var FirRegularClass.isNewPlaceForBodyGeneration: Boolean? by FirDeclarationDataR val FirCallableDeclaration.isIntersectionOverride: Boolean get() = origin == FirDeclarationOrigin.IntersectionOverride val FirCallableDeclaration.isSubstitutionOverride: Boolean get() = origin is FirDeclarationOrigin.SubstitutionOverride val FirCallableDeclaration.isSubstitutionOrIntersectionOverride: Boolean get() = isSubstitutionOverride || isIntersectionOverride +val FirCallableDeclaration.isDelegated: Boolean get() = origin == FirDeclarationOrigin.Delegated val FirCallableSymbol<*>.isIntersectionOverride: Boolean get() = origin == FirDeclarationOrigin.IntersectionOverride val FirCallableSymbol<*>.isSubstitutionOverride: Boolean get() = origin is FirDeclarationOrigin.SubstitutionOverride diff --git a/compiler/testData/ir/irText/firProblems/substitutionOverrideWithDelegate.fir.ir.txt b/compiler/testData/ir/irText/firProblems/substitutionOverrideWithDelegate.fir.ir.txt new file mode 100644 index 00000000000..902434e0b1a --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/substitutionOverrideWithDelegate.fir.ir.txt @@ -0,0 +1,131 @@ +FILE fqName: fileName:/substitutionOverrideWithDelegate.kt + FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Unit declared in ' + CALL 'public open fun invoke (): kotlin.Unit declared in .DelegatedB' type=kotlin.Unit origin=null + $this: CONSTRUCTOR_CALL 'public constructor () declared in .DelegatedB' type=.DelegatedB origin=null + CLASS INTERFACE name:A modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + FUN name:invoke visibility:public modality:OPEN <> ($this:.A) returnType:kotlin.Unit [operator] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + FUN name:invoke visibility:public modality:OPEN <> ($this:.A, value:kotlin.String) returnType:kotlin.Unit [operator] + $this: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:value index:0 type:kotlin.String + BLOCK_BODY + RETURN type=kotlin.Nothing from='public open fun invoke (value: kotlin.String): kotlin.Unit declared in .A' + CALL 'public final fun bar (value: kotlin.String): kotlin.Unit declared in ' type=kotlin.Unit origin=null + $receiver: GET_VAR ': .A declared in .A.invoke' type=.A origin=null + value: GET_VAR 'value: kotlin.String declared in .A.invoke' type=kotlin.String origin=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 + FUN name:bar visibility:public modality:FINAL <> ($receiver:.A, value:kotlin.String) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:value index:0 type:kotlin.String + BLOCK_BODY + CLASS CLASS name:DelegatedB modality:OPEN visibility:public superTypes:[.B] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.DelegatedB + CONSTRUCTOR visibility:public <> () returnType:.DelegatedB [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:DelegatedB modality:OPEN visibility:public superTypes:[.B]' + FUN DELEGATED_MEMBER name:invoke visibility:public modality:OPEN <> ($this:.DelegatedB) returnType:kotlin.Unit [operator] + overridden: + public open fun invoke (): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.DelegatedB + BLOCK_BODY + CALL 'public open fun invoke (): kotlin.Unit declared in .A' type=kotlin.Unit origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.C visibility:private [final]' type=.C origin=null + receiver: GET_VAR ': .DelegatedB declared in .DelegatedB.invoke' type=.DelegatedB origin=null + FUN DELEGATED_MEMBER name:invoke visibility:public modality:OPEN <> ($this:.DelegatedB, value:kotlin.String) returnType:kotlin.Unit [operator] + overridden: + public open fun invoke (value: kotlin.String): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.DelegatedB + VALUE_PARAMETER name:value index:0 type:kotlin.String + BLOCK_BODY + CALL 'public open fun invoke (value: kotlin.String): kotlin.Unit declared in .A' type=kotlin.Unit origin=null + $this: GET_FIELD 'FIELD DELEGATE name:$$delegate_0 type:.C visibility:private [final]' type=.C origin=null + receiver: GET_VAR ': .DelegatedB declared in .DelegatedB.invoke' type=.DelegatedB origin=null + value: GET_VAR 'value: kotlin.String declared in .DelegatedB.invoke' type=kotlin.String origin=null + FIELD DELEGATE name:$$delegate_0 type:.C visibility:private [final] + EXPRESSION_BODY + CONSTRUCTOR_CALL 'public constructor () declared in .C' type=.C origin=null + : kotlin.String + 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 .B + $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 .B + $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 .B + $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.B> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[kotlin.Any?] reified:false + FUN FAKE_OVERRIDE name:invoke visibility:public modality:OPEN <> ($this:.A) returnType:kotlin.Unit [fake_override,operator] + overridden: + public open fun invoke (): kotlin.Unit declared in .A + $this: VALUE_PARAMETER name: type:.A + FUN FAKE_OVERRIDE name:invoke visibility:public modality:OPEN <> ($this:.A, value:kotlin.String) returnType:kotlin.Unit [fake_override,operator] + overridden: + public open fun invoke (value: kotlin.String): kotlin.Unit declared in .A + $this: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:value index:0 type:kotlin.String + 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 CLASS name:C modality:FINAL visibility:public superTypes:[.B.C>] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C.C> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[kotlin.Any?] reified:false + CONSTRUCTOR visibility:public <> () returnType:.C.C> [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[.B.C>]' + FUN FAKE_OVERRIDE name:invoke visibility:public modality:OPEN <> ($this:.A) returnType:kotlin.Unit [fake_override,operator] + overridden: + public open fun invoke (): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.A + FUN FAKE_OVERRIDE name:invoke visibility:public modality:OPEN <> ($this:.A, value:kotlin.String) returnType:kotlin.Unit [fake_override,operator] + overridden: + public open fun invoke (value: kotlin.String): kotlin.Unit declared in .B + $this: VALUE_PARAMETER name: type:.A + VALUE_PARAMETER name:value index:0 type:kotlin.String + 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 .B + $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 .B + $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 .B + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/firProblems/substitutionOverrideWithDelegate.fir.kt.txt b/compiler/testData/ir/irText/firProblems/substitutionOverrideWithDelegate.fir.kt.txt new file mode 100644 index 00000000000..7ccb128e122 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/substitutionOverrideWithDelegate.fir.kt.txt @@ -0,0 +1,48 @@ +fun foo() { + return DelegatedB().invoke() +} + +interface A { + operator fun invoke() { + } + + operator fun invoke(value: String) { + return .bar(value = value) + } + +} + +fun A.bar(value: String) { +} + +open class DelegatedB : B { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + override operator fun invoke() { + .#$$delegate_0.invoke() + } + + override operator fun invoke(value: String) { + .#$$delegate_0.invoke(value = value) + } + + private /* final field */ val $$delegate_0: C = C() + +} + +interface B : A { + +} + +class C : B { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +}