From cac69edff25e6c6fe2cd3a9fa81846b97a0c1a69 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Mon, 11 Oct 2021 13:18:09 +0300 Subject: [PATCH] FIR: Fix forEach resolution within local class --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 +++++ .../body/resolve/BodyResolveContext.kt | 1 + .../resolve/forEachInLocalClass.kt | 25 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 6 files changed, 50 insertions(+) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt 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 1d41a3d9c5e..1efc464e8c2 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 @@ -36735,6 +36735,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("forEachInLocalClass.kt") + public void testForEachInLocalClass() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt"); + } + @Test @TestMetadata("hidesMembers.kt") public void testHidesMembers() 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 90cd7cab772..5474982f75d 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 @@ -36799,6 +36799,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("forEachInLocalClass.kt") + public void testForEachInLocalClass() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt"); + } + @Test @TestMetadata("hidesMembers.kt") public void testHidesMembers() 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 6285dbe0d3e..031973c9035 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 @@ -36799,6 +36799,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("forEachInLocalClass.kt") + public void testForEachInLocalClass() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt"); + } + @Test @TestMetadata("hidesMembers.kt") public void testHidesMembers() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt index 74549cc1cf9..e9dcadb79bf 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/BodyResolveContext.kt @@ -333,6 +333,7 @@ class BodyResolveContext( ): BodyResolveContext = BodyResolveContext(returnTypeCalculator, dataFlowAnalyzerContext, targetedLocalClasses, outerLocalClassForNested).apply { file = this@BodyResolveContext.file + fileImportsScope += this@BodyResolveContext.fileImportsScope towerDataContextForAnonymousFunctions.putAll(this@BodyResolveContext.towerDataContextForAnonymousFunctions) towerDataContextForCallableReferences.putAll(this@BodyResolveContext.towerDataContextForCallableReferences) containers = this@BodyResolveContext.containers diff --git a/compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt b/compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt new file mode 100644 index 00000000000..a75d23d6dac --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt @@ -0,0 +1,25 @@ +// SKIP_TXT +// FIR_IDENTICAL +// FULL_JDK +// !CHECK_TYPE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE + +// FILE: A.java +import java.util.List; +public class A { + public static List foo() { return null; } +} + +// FILE: main.kt + +fun bar(): Int { + return object { + fun baz(): Int { + val strings = A.foo() + strings.forEach { + if (it.length == 0) return 1 + } + return 2 + } + }.baz() +} 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 de42d30096c..0b042133368 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 @@ -36895,6 +36895,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/resolve"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); } + @Test + @TestMetadata("forEachInLocalClass.kt") + public void testForEachInLocalClass() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/resolve/forEachInLocalClass.kt"); + } + @Test @TestMetadata("hidesMembers.kt") public void testHidesMembers() throws Exception {