From c21e699783dadfab8ed98ca2844c6a70ae820111 Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Thu, 24 Oct 2019 11:04:16 +0300 Subject: [PATCH] Fix default type of static classes inside parametrized parents Default type of LazySubstitutingClassDescriptor is not lazy. However, most of default types are, and there is an optimization in KotlinTypeFactory, which uses default type for simple type without type arguments and/or annotations. LazySubstitutingClassDescriptor's default type creates simple type with factory, which may therefore cause recursion. #KT-34029 Fixed --- .../fir/FirDiagnosticsSmokeTestGenerated.java | 5 +++++ .../tests/inference/regressions/kt34029.kt | 6 ++++++ .../tests/inference/regressions/kt34029.txt | 18 ++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 5 +++++ .../DiagnosticsUsingJavacTestGenerated.java | 5 +++++ .../impl/LazySubstitutingClassDescriptor.java | 8 +++++++- 6 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt34029.txt diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java index 3e183f414de..42ee83b5138 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsSmokeTestGenerated.java @@ -10779,6 +10779,11 @@ public class FirDiagnosticsSmokeTestGenerated extends AbstractFirDiagnosticsSmok runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3344.kt"); } + @TestMetadata("kt34029.kt") + public void testKt34029() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt"); + } + @TestMetadata("kt34282.kt") public void testKt34282() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt34282.kt"); diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt new file mode 100644 index 00000000000..1c0c36585cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt @@ -0,0 +1,6 @@ +open class MyClass { + object MyObject : MyClass() { } +} + +val foo1 = MyClass.MyObject // it's ok +val foo2 = MyClass.MyObject // here's stofl diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt34029.txt b/compiler/testData/diagnostics/tests/inference/regressions/kt34029.txt new file mode 100644 index 00000000000..1efd47201de --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt34029.txt @@ -0,0 +1,18 @@ +package + +public val foo1: MyClass.MyObject +public val foo2: [ERROR : Type for MyClass.MyObject] + +public open class MyClass { + public constructor MyClass() + 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 object MyObject : MyClass { + private constructor MyObject() + 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/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 0caf95eefa4..276122fcf03 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10786,6 +10786,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3344.kt"); } + @TestMetadata("kt34029.kt") + public void testKt34029() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt"); + } + @TestMetadata("kt34282.kt") public void testKt34282() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt34282.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java index d4e1cf542f3..694899e0ecc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsUsingJavacTestGenerated.java @@ -10781,6 +10781,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing runTest("compiler/testData/diagnostics/tests/inference/regressions/kt3344.kt"); } + @TestMetadata("kt34029.kt") + public void testKt34029() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/regressions/kt34029.kt"); + } + @TestMetadata("kt34282.kt") public void testKt34282() throws Exception { runTest("compiler/testData/diagnostics/tests/inference/regressions/kt34282.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java index 2e61b652896..9de9cc8dec7 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/impl/LazySubstitutingClassDescriptor.java @@ -141,7 +141,13 @@ public class LazySubstitutingClassDescriptor extends ModuleAwareClassDescriptor @Override public SimpleType getDefaultType() { List typeProjections = TypeUtils.getDefaultTypeProjections(getTypeConstructor().getParameters()); - return KotlinTypeFactory.simpleNotNullType(getAnnotations(), this, typeProjections); + return KotlinTypeFactory.simpleTypeWithNonTrivialMemberScope( + getAnnotations(), + getTypeConstructor(), + typeProjections, + false, + getUnsubstitutedMemberScope() + ); } @NotNull