From 3f02309dadd5b3588e69ffd5cc7bbb1604a55d92 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Tue, 21 Dec 2021 13:23:53 +0300 Subject: [PATCH] FIR: add example 2 from KT-49925 (fails yet) --- ...nosisCompilerFirTestdataTestGenerated.java | 6 +++ .../problems/buildSetWithVisitor.fir.txt | 46 +++++++++++++++++++ .../inference/problems/buildSetWithVisitor.kt | 24 ++++++++++ .../runners/FirDiagnosticTestGenerated.java | 6 +++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++ 5 files changed, 88 insertions(+) create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.fir.txt create mode 100644 compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.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 44d5be2e5fd..5bf59c75fc0 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 @@ -5142,6 +5142,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildList.kt"); } + @Test + @TestMetadata("buildSetWithVisitor.kt") + public void testBuildSetWithVisitor() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.kt"); + } + @Test @TestMetadata("expectedType.kt") public void testExpectedType() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.fir.txt new file mode 100644 index 00000000000..b5d0c2442ef --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.fir.txt @@ -0,0 +1,46 @@ +FILE: buildSetWithVisitor.kt + public abstract class AnyVisitor : R|kotlin/Any| { + public constructor(): R|AnyVisitor| { + super() + } + + public abstract fun visit(arg: R|Wrapper|): R|kotlin/Unit| + + } + public final class Wrapper : R|kotlin/Any| { + public constructor(tag: R|kotlin/String|): R|Wrapper| { + super() + } + + public final val tag: R|kotlin/String| = R|/tag| + public get(): R|kotlin/String| + + } + public final fun R|Wrapper|.accept(visitor: R|AnyVisitor|): R|kotlin/Unit| { + R|/visitor|.R|/AnyVisitor.visit|(this@R|/accept|) + } + public final fun bar(wrapper: R|Wrapper|): R|kotlin/collections/Set| { + ^bar #( = buildSet@fun R|kotlin/collections/MutableSet|.(): R|kotlin/Unit| { + R|/wrapper|.R|/accept|(object : R|AnyVisitor| { + private constructor(): R|| { + super() + } + + public final override fun visit(arg: R|Wrapper|): R|kotlin/Unit| { + this@R|special/anonymous|.R|SubstitutionOverride|(R|/arg|.R|/Wrapper.tag|) + } + + } + ) + } + ) + } + public final fun foo(wrapper: R|Wrapper|): R|kotlin/collections/Set| { + ^foo R|kotlin/collections/buildSet|( = buildSet@fun R|kotlin/collections/MutableSet|.(): R|kotlin/Unit| { + R|/wrapper|.R|kotlin/let|( = let@fun (it: R|Wrapper|): R|kotlin/Unit| { + this@R|special/anonymous|.R|SubstitutionOverride|(R|/it|.R|/Wrapper.tag|) + } + ) + } + ) + } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.kt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.kt new file mode 100644 index 00000000000..3dd0aa5fd14 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.kt @@ -0,0 +1,24 @@ +abstract class AnyVisitor { + abstract fun visit(arg: Wrapper) +} + +class Wrapper(val tag: String) + +fun Wrapper.accept(visitor: AnyVisitor) { + visitor.visit(this) +} + +fun bar(wrapper: Wrapper) = buildSet { + wrapper.accept(object : AnyVisitor() { + override fun visit(arg: Wrapper) { + add(arg.tag) + } + }) +} + +fun foo(wrapper: Wrapper) = buildSet { + wrapper.let { + add(it.tag) + } +} + 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 a32f917ad34..e9d8f8788bf 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 @@ -5142,6 +5142,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest { runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildList.kt"); } + @Test + @TestMetadata("buildSetWithVisitor.kt") + public void testBuildSetWithVisitor() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.kt"); + } + @Test @TestMetadata("expectedType.kt") public void testExpectedType() throws Exception { 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 29fc881cefc..dabad62f71b 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 @@ -5142,6 +5142,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildList.kt"); } + @Test + @TestMetadata("buildSetWithVisitor.kt") + public void testBuildSetWithVisitor() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/inference/problems/buildSetWithVisitor.kt"); + } + @Test @TestMetadata("expectedType.kt") public void testExpectedType() throws Exception {