diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt index a2a28912e52..08668ee61a1 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilder.kt @@ -35,9 +35,9 @@ interface ControlFlowBuilder { val returnSubroutine: KtElement // Lexical scopes - fun enterLexicalScope(element: KtElement) + fun enterLexicalScope(block: KtElement) - fun exitLexicalScope(element: KtElement) + fun exitLexicalScope(block: KtElement) fun getExitPoint(labelElement: KtElement): Label? fun getConditionEntryPoint(labelElement: KtElement): Label diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt index 0f2c4ba3722..ce2107d5ad8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowBuilderAdapter.kt @@ -217,11 +217,11 @@ abstract class ControlFlowBuilderAdapter : ControlFlowBuilder { return delegateBuilder.newValue(element) } - override fun enterLexicalScope(element: KtElement) { - delegateBuilder.enterLexicalScope(element) + override fun enterLexicalScope(block: KtElement) { + delegateBuilder.enterLexicalScope(block) } - override fun exitLexicalScope(element: KtElement) { - delegateBuilder.exitLexicalScope(element) + override fun exitLexicalScope(block: KtElement) { + delegateBuilder.exitLexicalScope(block) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt index 19589040c3e..c74553e329b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/ControlFlowInstructionsGenerator.kt @@ -179,18 +179,18 @@ class ControlFlowInstructionsGenerator : ControlFlowBuilderAdapter() { private val currentScope: LexicalScope get() = lexicalScopes.peek() - override fun enterLexicalScope(element: KtElement) { + override fun enterLexicalScope(block: KtElement) { val current = if (lexicalScopes.isEmpty()) null else currentScope - val scope = LexicalScope(current, element) + val scope = LexicalScope(current, block) lexicalScopes.push(scope) } - override fun exitLexicalScope(element: KtElement) { + override fun exitLexicalScope(block: KtElement) { val currentScope = currentScope - assert(currentScope.element === element) { + assert(currentScope.block === block) { "Exit from not the current lexical scope.\n" + - "Current scope is for: " + currentScope.element + ".\n" + - "Exit from the scope for: " + element.text + "Current scope is for a block: " + currentScope.block.text + ".\n" + + "Exit from the scope for: " + block.text } lexicalScopes.pop() } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/LexicalScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/LexicalScope.kt index bec174fc317..743b7a4597c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/LexicalScope.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/pseudocode/instructions/LexicalScope.kt @@ -19,20 +19,17 @@ package org.jetbrains.kotlin.cfg.pseudocode.instructions import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtElement -class LexicalScope(val parentScope: LexicalScope?, val element: KtElement) { - //todo remove after KT-4126 - private val d = (parentScope?.depth ?: 0) + 1 - val depth: Int get() = d +class LexicalScope(private val parentScope: LexicalScope?, val block: KtElement) { + val depth: Int = (parentScope?.depth ?: 0) + 1 val lexicalScopeForContainingDeclaration: LexicalScope? by lazy { var scope: LexicalScope? = this while (scope != null) { - if (scope.element is KtDeclaration) { - return@lazy scope + if (scope.block is KtDeclaration) { + break } scope = scope.parentScope } - - return@lazy null + scope } }