From ada7f3da6ca9b9c5fc6b2cbb2ebf23db7d3aef22 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 19 Dec 2019 14:57:45 +0300 Subject: [PATCH] FIR: resolve anonymous initializer in context independent mode --- .../FirDeclarationsResolveTransformer.kt | 2 +- .../resolve/stdlib/runOnIntegerLiteral.kt | 8 ++++++++ .../resolve/stdlib/runOnIntegerLiteral.txt | 17 +++++++++++++++++ .../FirDiagnosticsWithStdlibTestGenerated.java | 5 +++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.kt create mode 100644 compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.txt diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index a15eb4a46b0..97128c087d5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -372,7 +372,7 @@ class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer) return withScopeCleanup(localScopes) { dataFlowAnalyzer.enterInitBlock(anonymousInitializer) localScopes.addIfNotNull(primaryConstructorParametersScope) - transformDeclaration(anonymousInitializer, data).also { + transformDeclaration(anonymousInitializer, ResolutionMode.ContextIndependent).also { dataFlowAnalyzer.exitInitBlock(it.single as FirAnonymousInitializer) } } diff --git a/compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.kt b/compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.kt new file mode 100644 index 00000000000..ad72a5de69a --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.kt @@ -0,0 +1,8 @@ +class TestInitValInLambdaCalledOnce { + val x: Int + init { + 1.run { + x = 0 + } + } +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.txt b/compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.txt new file mode 100644 index 00000000000..f3f4f8c9826 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.txt @@ -0,0 +1,17 @@ +FILE: runOnIntegerLiteral.kt + public final class TestInitValInLambdaCalledOnce : R|kotlin/Any| { + public constructor(): R|TestInitValInLambdaCalledOnce| { + super() + } + + public final val x: R|kotlin/Int| + public get(): R|kotlin/Int| + + init { + Int(1).R|kotlin/run|( = run@fun R|kotlin/Int|.(): R|kotlin/Nothing| { + this@R|/TestInitValInLambdaCalledOnce|.R|/TestInitValInLambdaCalledOnce.x| = Int(0) + } + ) + } + + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java index 57e504672de..5e87d21157a 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithStdlibTestGenerated.java @@ -173,6 +173,11 @@ public class FirDiagnosticsWithStdlibTestGenerated extends AbstractFirDiagnostic runTest("compiler/fir/resolve/testData/resolve/stdlib/reflectionClass.kt"); } + @TestMetadata("runOnIntegerLiteral.kt") + public void testRunOnIntegerLiteral() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/stdlib/runOnIntegerLiteral.kt"); + } + @TestMetadata("simpleDelegateProvider.kt") public void testSimpleDelegateProvider() throws Exception { runTest("compiler/fir/resolve/testData/resolve/stdlib/simpleDelegateProvider.kt");