From e872cfa69a8ed4ec26f0fa5078f3d7ed1909d01b Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 21 Dec 2021 12:29:13 +0300 Subject: [PATCH] FIR: add test repeating problem from KT-50470 --- ...nosisCompilerFirTestdataTestGenerated.java | 16 +++++ .../inference/problems/expectedType.fir.txt | 72 +++++++++++++++++++ .../inference/problems/expectedType.kt | 31 ++++++++ .../runners/FirDiagnosticTestGenerated.java | 16 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 16 +++++ 5 files changed, 151 insertions(+) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 7d418ee377c..3759b824b08 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -5126,6 +5126,22 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis public void testPlusAssignWithLambdaInRhs() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.kt"); } + + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems") + @TestDataPath("$PROJECT_ROOT") + public class Problems { + @Test + public void testAllFilesPresentInProblems() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("expectedType.kt") + public void testExpectedType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt"); + } + } } @Nested diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.fir.txt new file mode 100644 index 00000000000..88e022bc5e3 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.fir.txt @@ -0,0 +1,72 @@ +FILE: expectedType.kt + public abstract class FirProperty : R|kotlin/Any| { + public constructor(): R|FirProperty| { + super() + } + + public abstract val returnTypeRef: R|FirTypeRef| + public get(): R|FirTypeRef| + + } + public abstract class FirTypeRef : R|kotlin/Any| { + public constructor(): R|FirTypeRef| { + super() + } + + } + public abstract class FirResolvedTypeRef : R|FirTypeRef| { + public constructor(): R|FirResolvedTypeRef| { + super() + } + + public abstract val type: R|ConeKotlinType| + public get(): R|ConeKotlinType| + + } + public abstract class ConeKotlinType : R|kotlin/Any| { + public constructor(): R|ConeKotlinType| { + super() + } + + } + public final inline fun R|FirTypeRef|.coneTypeSafe(): R|C?| { + ^coneTypeSafe ((this@R|/coneTypeSafe| as? R|FirResolvedTypeRef|)?.{ $subj$.R|/FirResolvedTypeRef.type| } as? R|C|) + } + public final fun myLazy(initializer: R|() -> L|): R|MyLazy| { + ^myLazy R|/MyLazy.MyLazy|(R|/initializer|) + } + public final operator fun R|MyLazy|.getValue(thisRef: R|kotlin/Any?|, property: R|kotlin/reflect/KProperty<*>|): R|V| { + ^getValue this@R|/getValue|.R|SubstitutionOverride| + } + public final class MyLazy : R|kotlin/Any| { + public constructor(initializer: R|() -> M|): R|MyLazy| { + super() + } + + private final var _value: R|kotlin/Any?| = Null(null) + private get(): R|kotlin/Any?| + private set(value: R|kotlin/Any?|): R|kotlin/Unit| + + public final val value: R|M| + public get(): R|M| { + ^ (this@R|/MyLazy|.R|/MyLazy._value| as R|M|) + } + + } + public final class Session : R|kotlin/Any| { + public constructor(property: R|FirProperty|): R|Session| { + super() + } + + public final val property: R|FirProperty| = R|/property| + public get(): R|FirProperty| + + public final val expectedType: R|ConeKotlinType?|by #( = myLazy@fun (): R|ConeKotlinType| { + ^ this@R|/Session|.R|/Session.property|.R|/FirProperty.returnTypeRef|.#() + } + ) + public get(): R|ConeKotlinType?| { + ^ this@R|/Session|.D|/Session.expectedType|.R|/getValue|(this@R|/Session|, ::R|/Session.expectedType|) + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt new file mode 100644 index 00000000000..ae6e88b9b21 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt @@ -0,0 +1,31 @@ +import kotlin.reflect.KProperty + +abstract class FirProperty { + abstract val returnTypeRef: FirTypeRef +} + +abstract class FirTypeRef + +abstract class FirResolvedTypeRef : FirTypeRef() { + abstract val type: ConeKotlinType +} + +abstract class ConeKotlinType + +inline fun FirTypeRef.coneTypeSafe(): C? { + return (this as? FirResolvedTypeRef)?.type as? C +} + +public fun myLazy(initializer: () -> L): MyLazy = MyLazy(initializer) + +public operator fun MyLazy.getValue(thisRef: Any?, property: KProperty<*>): V = value + +class MyLazy(initializer: () -> M) { + private var _value: Any? = null + + val value: M get() = _value as M +} + +class Session(val property: FirProperty) { + val expectedType: ConeKotlinType? by myLazy { property.returnTypeRef.coneTypeSafe() } +} diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java index 098975860c6..2a61f7df755 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticTestGenerated.java @@ -5126,6 +5126,22 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testPlusAssignWithLambdaInRhs() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.kt"); } + + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems") + @TestDataPath("$PROJECT_ROOT") + public class Problems { + @Test + public void testAllFilesPresentInProblems() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("expectedType.kt") + public void testExpectedType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt"); + } + } } @Nested diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java index 40fadc30c89..1be72b18033 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirDiagnosticsWithLightTreeTestGenerated.java @@ -5126,6 +5126,22 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testPlusAssignWithLambdaInRhs() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/plusAssignWithLambdaInRhs.kt"); } + + @Nested + @TestMetadata("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems") + @TestDataPath("$PROJECT_ROOT") + public class Problems { + @Test + public void testAllFilesPresentInProblems() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems"), Pattern.compile("^([^.]+)\\.kt$"), null, true); + } + + @Test + @TestMetadata("expectedType.kt") + public void testExpectedType() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/expectedType.kt"); + } + } } @Nested