From 0e050ae7f1860a1cfe1559d5a06640dc7efc777d Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Fri, 18 Nov 2022 01:16:29 +0900 Subject: [PATCH] [FE] Consider derived class tag on caching substitution scopes --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++ .../fir/scopes/FirKotlinScopeProvider.kt | 17 +++++-- .../tests/subtyping/delegatedConstructor.kt | 29 ++++++++++++ .../tests/subtyping/delegatedConstructor.txt | 46 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++ 7 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt create mode 100644 compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index d3f8e22499a..0411b38411b 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -31232,6 +31232,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/subtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("delegatedConstructor.kt") + public void testDelegatedConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt"); + } + @Test @TestMetadata("extFunctionTypeAsSuperType.kt") public void testExtFunctionTypeAsSuperType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 49eef1069c6..d9624a5cae2 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -31328,6 +31328,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/subtyping"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("delegatedConstructor.kt") + public void testDelegatedConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt"); + } + @Test @TestMetadata("extFunctionTypeAsSuperType.kt") public void testExtFunctionTypeAsSuperType() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index 8907478e602..efa76a75c9a 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -31232,6 +31232,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/subtyping"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("delegatedConstructor.kt") + public void testDelegatedConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt"); + } + @Test @TestMetadata("extFunctionTypeAsSuperType.kt") public void testExtFunctionTypeAsSuperType() throws Exception { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt index e342bb1f6ce..aea9a8a0ab9 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/FirKotlinScopeProvider.kt @@ -83,7 +83,10 @@ class FirKotlinScopeProvider( data class ConeSubstitutionScopeKey( - val lookupTag: ConeClassLikeLookupTag, val isFromExpectClass: Boolean, val substitutor: ConeSubstitutor + val lookupTag: ConeClassLikeLookupTag, + val isFromExpectClass: Boolean, + val substitutor: ConeSubstitutor, + val derivedClassLookupTag: ConeClassLikeLookupTag? ) : ScopeSessionKey() fun FirClass.unsubstitutedScope( @@ -162,10 +165,14 @@ private fun FirClass.scopeForClassImpl( val basicScope = unsubstitutedScope(useSiteSession, scopeSession, withForcedTypeCalculator = false) if (substitutor == ConeSubstitutor.Empty) return basicScope - val key = ConeSubstitutionScopeKey(classFirDispatchReceiver.symbol.toLookupTag(), isFromExpectClass, substitutor) - return scopeSession.getOrBuild( - this, key - ) { + val key = ConeSubstitutionScopeKey( + classFirDispatchReceiver.symbol.toLookupTag(), + isFromExpectClass, + substitutor, + derivedClassLookupTag + ) + + return scopeSession.getOrBuild(this, key) { FirClassSubstitutionScope( useSiteSession, basicScope, diff --git a/compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt b/compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt new file mode 100644 index 00000000000..fa46ea682bb --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt @@ -0,0 +1,29 @@ +// FIR_IDENTICAL + +// MODULE: lib + +// FILE: lib.kt +package lib + +abstract class Base + + +// MODULE: test(lib) + +// FILE: foo.kt +package test + +import lib.Base + +class Foo { + private inner class FooImpl : Base() +} + +// FILE: bar.kt +package test + +import lib.Base + +class Bar { + private inner class BarImpl : Base() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.txt b/compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.txt new file mode 100644 index 00000000000..123538f7060 --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.txt @@ -0,0 +1,46 @@ +// -- Module: -- +package + +package lib { + + public abstract class Base { + public constructor Base() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +// -- Module: -- +package + +package test { + + public final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + private final inner class BarImpl : lib.Base { + public constructor BarImpl() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } + + public final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + private final inner class FooImpl : lib.Base { + public constructor FooImpl() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index e67d084caf0..d828e24474c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -31328,6 +31328,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/subtyping"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("delegatedConstructor.kt") + public void testDelegatedConstructor() throws Exception { + runTest("compiler/testData/diagnostics/tests/subtyping/delegatedConstructor.kt"); + } + @Test @TestMetadata("extFunctionTypeAsSuperType.kt") public void testExtFunctionTypeAsSuperType() throws Exception {