From ca98417a0c7d04a286d608d513dc3f0a848d8c67 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 9 Aug 2021 10:26:50 +0300 Subject: [PATCH] FIR: add test for erroneous type inference in UAST (KT-48159) --- .../intellij/UastPatterns.fir.txt | 42 +++++++++++++++++++ .../intellij/UastPatterns.kt | 38 +++++++++++++++++ .../runners/FirDiagnosticTestGenerated.java | 6 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++ ...nosisCompilerFirTestdataTestGenerated.java | 6 +++ 5 files changed, 98 insertions(+) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt new file mode 100644 index 00000000000..4ffe3fcced3 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.fir.txt @@ -0,0 +1,42 @@ +FILE: UastPatterns.kt + public abstract interface UElement : R|kotlin/Any| { + } + public abstract interface UExpression : R|UElement| { + } + public abstract interface UReferenceExpression : R|UExpression| { + } + public final fun injectionHostOrReferenceExpression(): R|UExpressionPattern.Capture| { + ^injectionHostOrReferenceExpression R|/uExpression|().#( = filter@fun (it: R|UExpression|): R|kotlin/Boolean| { + ^ (R|/it| is R|UReferenceExpression|) + } + ) + } + public final fun uExpression(): R|UExpressionPattern.Capture| { + ^uExpression R|/expressionCapture|((Q|UExpression|).R|kotlin/jvm/java|) + } + public final fun expressionCapture(clazz: R|java/lang/Class|): R|UExpressionPattern.Capture| { + ^expressionCapture Q|UExpressionPattern|.R|SubstitutionOverride|(R|/clazz|) + } + public open class UElementPattern|> : R|ObjectPattern| { + public constructor|>(clazz: R|java/lang/Class|): R|UElementPattern| { + super|>(R|/clazz|) + } + + public final fun filter(filter: R|(T) -> kotlin/Boolean|): R|Self| { + ^filter (this@R|/UElementPattern| as R|Self|) + } + + } + public open class UExpressionPattern|> : R|UElementPattern| { + public constructor|>(clazz: R|java/lang/Class|): R|UExpressionPattern| { + super|>(R|/clazz|) + } + + public open class Capture : R|UExpressionPattern>| { + public constructor(clazz: R|java/lang/Class|): R|UExpressionPattern.Capture| { + super>|>(R|/clazz|) + } + + } + + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt new file mode 100644 index 00000000000..16d99039c48 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt @@ -0,0 +1,38 @@ +// FILE: ObjectPattern.java + +import org.jetbrains.annotations.NotNull; + +public abstract class ObjectPattern> { + protected ObjectPattern(@NotNull Class aClass) { + + } + + public static class Capture extends ObjectPattern> { + public Capture(@NotNull Class aClass) { + super(aClass); + } + } +} + +// FILE: UastPatterns.kt + +interface UElement + +interface UExpression : UElement + +interface UReferenceExpression : UExpression + +fun injectionHostOrReferenceExpression(): UExpressionPattern.Capture = + uExpression().filter { it is UReferenceExpression } + +fun uExpression(): UExpressionPattern.Capture = expressionCapture(UExpression::class.java) + +fun expressionCapture(clazz: Class): UExpressionPattern.Capture = UExpressionPattern.Capture(clazz) + +open class UElementPattern>(clazz: Class) : ObjectPattern(clazz) { + fun filter(filter: (T) -> Boolean): Self = this as Self +} + +open class UExpressionPattern>(clazz: Class) : UElementPattern(clazz) { + open class Capture(clazz: Class) : UExpressionPatternCapture>(clazz) +} \ No newline at end of file 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 b35c3f24252..670f5f8ec63 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 @@ -5044,6 +5044,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { public void testEnumWithToString() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/EnumWithToString.kt"); } + + @Test + @TestMetadata("UastPatterns.kt") + public void testUastPatterns() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.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 8256bf9f9f0..1287f6bacbe 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 @@ -5044,6 +5044,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos public void testEnumWithToString() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/EnumWithToString.kt"); } + + @Test + @TestMetadata("UastPatterns.kt") + public void testUastPatterns() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt"); + } } @Nested diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java index 11f3a1dfa09..a7ee81b3954 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/tests/org/jetbrains/kotlin/idea/fir/low/level/api/diagnostic/compiler/based/DiagnosisCompilerFirTestdataTestGenerated.java @@ -5044,6 +5044,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis public void testEnumWithToString() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/EnumWithToString.kt"); } + + @Test + @TestMetadata("UastPatterns.kt") + public void testUastPatterns() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/UastPatterns.kt"); + } } @Nested