diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index fa4d265e80f..4a2fd8bb33a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -54,7 +54,6 @@ public class JetControlFlowProcessor { this.trace = trace; } - //todo public Pseudocode generatePseudocode(@NotNull JetDeclaration subroutine) { Pseudocode pseudocode = generate(subroutine); ((PseudocodeImpl)pseudocode).postProcess(); @@ -64,7 +63,7 @@ public class JetControlFlowProcessor { return pseudocode; } - public Pseudocode generate(@NotNull JetDeclaration subroutine) { + private Pseudocode generate(@NotNull JetDeclaration subroutine) { builder.enterSubroutine(subroutine); if (subroutine instanceof JetDeclarationWithBody) { JetDeclarationWithBody declarationWithBody = (JetDeclarationWithBody) subroutine; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java index 8eb651cf4a0..74beb128229 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/PseudocodeImpl.java @@ -108,12 +108,18 @@ public class PseudocodeImpl implements Pseudocode { @Override public Set getLocalDeclarations() { if (localDeclarations == null) { - localDeclarations = Sets.newLinkedHashSet(); - //todo look recursively inside local declarations - for (Instruction instruction : instructions) { - if (instruction instanceof LocalDeclarationInstruction) { - localDeclarations.add((LocalDeclarationInstruction) instruction); - } + localDeclarations = getLocalDeclarations(this); + } + return localDeclarations; + } + + @NotNull + private static Set getLocalDeclarations(@NotNull Pseudocode pseudocode) { + Set localDeclarations = Sets.newHashSet(); + for (Instruction instruction : pseudocode.getInstructions()) { + if (instruction instanceof LocalDeclarationInstruction) { + localDeclarations.add((LocalDeclarationInstruction) instruction); + localDeclarations.addAll(getLocalDeclarations(((LocalDeclarationInstruction)instruction).getBody())); } } return localDeclarations; diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.jet b/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.jet new file mode 100644 index 00000000000..422e57181f6 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/checkInnerLocalDeclarations.jet @@ -0,0 +1,12 @@ +package c + +fun test() { + val x = 10 + fun inner1() { + fun inner2() { + fun inner3() { + val y = x + } + } + } +} \ No newline at end of file