From ae1622d059bef826f10ef1c54787ac58b678ced3 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Tue, 16 May 2023 20:32:38 +0200 Subject: [PATCH] [LL FIR] support lazy resolve for fake override declarations ^KT-58727 Fixed --- .../delegatedMemberScope/withImplicitType.pretty.txt | 4 ++-- .../delegatedMemberScope/withImplicitType.txt | 5 +++-- .../substitutionOverride.pretty.txt | 6 +++--- .../memberScopeByFqName/substitutionOverride.txt | 12 +++++++----- .../transformers/LLFirImplicitTypesLazyResolver.kt | 11 +++++++++-- .../delegation/WithImplicitType.java | 4 ++-- 6 files changed, 26 insertions(+), 16 deletions(-) diff --git a/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.pretty.txt index aa88cb1e726..59011be555d 100644 --- a/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.pretty.txt +++ b/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.pretty.txt @@ -1,3 +1,3 @@ -open fun foo(): ERROR(empty body) +open fun foo(): kotlin.Int -open fun bar(): kotlin.Int +open fun bar(): kotlin.Int \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.txt b/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.txt index 373987e9684..7f51bfbcea2 100644 --- a/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.txt +++ b/analysis/analysis-api/testData/components/scopeProvider/delegatedMemberScope/withImplicitType.txt @@ -17,9 +17,10 @@ KtFunctionSymbol: name: foo origin: DELEGATED receiverParameter: null - returnType: KtTypeErrorType: + returnType: KtUsualClassType: annotationsList: [] - type: ERROR CLASS: empty body + ownTypeArguments: [] + type: kotlin/Int symbolKind: CLASS_MEMBER typeParameters: [] valueParameters: [] diff --git a/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.pretty.txt b/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.pretty.txt index 23c47e502e5..af734b19da6 100644 --- a/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.pretty.txt +++ b/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.pretty.txt @@ -2,7 +2,7 @@ fun noGeneric(): kotlin.Int fun noGenericWithExplicitType(): kotlin.Int -fun withOuterGeneric(t: test.Foo): ERROR(empty body) +fun withOuterGeneric(t: test.Foo): kotlin.String fun withOuterGenericWithExplicitType(t: test.Foo): kotlin.String @@ -10,7 +10,7 @@ fun withOwnGeneric(tt: TT): kotlin.Boolean fun withOwnGenericWithExplicitType(tt: TT): kotlin.Boolean -fun withOuterAndOwnGeneric(t: test.Foo, tt: TT): ERROR(empty body) +fun withOuterAndOwnGeneric(t: test.Foo, tt: TT): kotlin.Long fun withOuterAndOwnGenericWithExplicitType(t: test.Foo, tt: TT): kotlin.Long @@ -20,4 +20,4 @@ open fun hashCode(): kotlin.Int open fun toString(): kotlin.String -constructor() +constructor() \ No newline at end of file diff --git a/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.txt b/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.txt index f3b3b434a85..af0007a960b 100644 --- a/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.txt +++ b/analysis/analysis-api/testData/components/scopeProvider/memberScopeByFqName/substitutionOverride.txt @@ -93,9 +93,10 @@ KtFunctionSymbol: name: withOuterGeneric origin: SUBSTITUTION_OVERRIDE receiverParameter: null - returnType: KtTypeErrorType: + returnType: KtUsualClassType: annotationsList: [] - type: ERROR CLASS: empty body + ownTypeArguments: [] + type: kotlin/String symbolKind: CLASS_MEMBER typeParameters: [] valueParameters: [ @@ -330,9 +331,10 @@ KtFunctionSymbol: name: withOuterAndOwnGeneric origin: SUBSTITUTION_OVERRIDE receiverParameter: null - returnType: KtTypeErrorType: + returnType: KtUsualClassType: annotationsList: [] - type: ERROR CLASS: empty body + ownTypeArguments: [] + type: kotlin/Long symbolKind: CLASS_MEMBER typeParameters: [ KtTypeParameterSymbol(TT) @@ -614,4 +616,4 @@ KtConstructorSymbol: valueParameters: [] visibility: Public getContainingModule: KtSourceModule "Sources of main" - deprecationStatus: null + deprecationStatus: null \ No newline at end of file diff --git a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirImplicitTypesLazyResolver.kt b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirImplicitTypesLazyResolver.kt index 1f02d31bad9..c3d42dde6d8 100644 --- a/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirImplicitTypesLazyResolver.kt +++ b/analysis/low-level-api-fir/src/org/jetbrains/kotlin/analysis/low/level/api/fir/transformers/LLFirImplicitTypesLazyResolver.kt @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirImplicitAwareBodyResolveTransformer import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirTowerDataContextCollector import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.ImplicitBodyResolveComputationSession +import org.jetbrains.kotlin.fir.scopes.fakeOverrideSubstitution import org.jetbrains.kotlin.fir.visitors.transformSingle internal object LLFirImplicitTypesLazyResolver : LLFirLazyResolver(FirResolvePhase.IMPLICIT_TYPES_BODY_RESOLVE) { @@ -91,10 +92,16 @@ internal class LLFirImplicitBodyTargetResolver( -> { // no implicit bodies here } + is FirCallableDeclaration -> { - calculateLazyBodies(target) - target.transformSingle(transformer, ResolutionMode.ContextIndependent) + if (target.attributes.fakeOverrideSubstitution != null) { + transformer.returnTypeCalculator.fakeOverrideTypeCalculator.computeReturnType(target) + } else { + calculateLazyBodies(target) + target.transformSingle(transformer, ResolutionMode.ContextIndependent) + } } + else -> throwUnexpectedFirElementError(target) } } diff --git a/compiler/testData/asJava/lightClasses/lightClassByFqName/delegation/WithImplicitType.java b/compiler/testData/asJava/lightClasses/lightClassByFqName/delegation/WithImplicitType.java index 25a23eaba91..381f8fb2c83 100644 --- a/compiler/testData/asJava/lightClasses/lightClassByFqName/delegation/WithImplicitType.java +++ b/compiler/testData/asJava/lightClasses/lightClassByFqName/delegation/WithImplicitType.java @@ -3,10 +3,10 @@ public final class A /* one.A*/ implements one.I { private final one.I p; @java.lang.Override() - public error.NonExistentClass foo();// foo() + public int bar();// bar() @java.lang.Override() - public int bar();// bar() + public int foo();// foo() public A(@org.jetbrains.annotations.NotNull() one.I);// .ctor(one.I) }