diff --git a/idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 5d8dfe15e30..031baed2986 100644 --- a/idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/idea/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -332,6 +332,7 @@ public class JetControlFlowProcessor { } builder.jump(loopEntryPoint); builder.exitLoop(expression); + builder.readUnit(expression); } @Override @@ -348,6 +349,7 @@ public class JetControlFlowProcessor { } builder.jumpOnTrue(loopEntryPoint); builder.exitLoop(expression); + builder.readUnit(expression); } @Override @@ -363,6 +365,7 @@ public class JetControlFlowProcessor { } builder.nondeterministicJump(loopEntryPoint); builder.exitLoop(expression); + builder.readUnit(expression); } @Override diff --git a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index 143bb9bd446..0b6e70069fa 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -366,7 +366,10 @@ public class TopDownAnalyzer { collectReachable(enterInstruction, visited); for (Instruction instruction : pseudocode.getInstructions()) { - if (!visited.contains(instruction) && instruction instanceof JetElementInstruction) { + if (!visited.contains(instruction) && + instruction instanceof JetElementInstruction && + // TODO : do {return} while (1 > a) + !(instruction instanceof ReadUnitValueInstruction)) { unreachableElements.add(((JetElementInstruction) instruction).getElement()); } } @@ -376,13 +379,6 @@ public class TopDownAnalyzer { public void collectDominatedExpressions(@NotNull JetExpression dominator, @NotNull Collection dominated) { Instruction dominatorInstruction = representativeInstructions.get(dominator); if (dominatorInstruction == null) { -// assert -// dominator instanceof JetContinueExpression || -// dominator instanceof JetBreakExpression || -// dominator instanceof JetReturnExpression || -// dominator instanceof JetBlockExpression || -// dominator instanceof JetFunctionLiteralExpression -// : "No representative instruction for a Nothing-typed expression: " + dominator.getText(); return; } SubroutineEnterInstruction enterInstruction = dominatorInstruction.getOwner().getEnterInstruction(); diff --git a/idea/testData/cfg/Finally.instructions b/idea/testData/cfg/Finally.instructions index f34ec57fe37..ff612f410fc 100644 --- a/idea/testData/cfg/Finally.instructions +++ b/idea/testData/cfg/Finally.instructions @@ -227,8 +227,9 @@ l4: l6: r(2) jmp(l3) -l1: l2: + read (Unit) +l1: ===================== == t3 == @@ -265,6 +266,7 @@ l5: l6: jmp(l4) l3: + read (Unit) r(5) l2: r(2) @@ -303,8 +305,9 @@ l5: read (Unit) l6: jmp(l4) -l2: l3: + read (Unit) +l2: r(2) l1: @@ -347,8 +350,9 @@ l4: l6: r(2) jmp?(l3) -l1: l2: + read (Unit) +l1: ===================== == t3 == @@ -388,6 +392,7 @@ l5: l6: jmp?(l4) l3: + read (Unit) r(5) l2: r(2) @@ -429,8 +434,9 @@ l5: read (Unit) l6: jmp?(l4) -l2: l3: + read (Unit) +l2: r(2) l1: diff --git a/idea/testData/cfg/OnlyWhileInFunctionBody.instructions b/idea/testData/cfg/OnlyWhileInFunctionBody.instructions new file mode 100644 index 00000000000..23c5c2fbee5 --- /dev/null +++ b/idea/testData/cfg/OnlyWhileInFunctionBody.instructions @@ -0,0 +1,42 @@ +== main == +fun main() { + while(1 > 0) { + 2 + } +} +--------------------- +l0: + +l3: + r(1) + r(0) + r(>) + r(1 > 0) + jf(l2) + r(2) + jmp(l3) +l2: + read (Unit) +l1: + +===================== +== dowhile == +fun dowhile() { + do {return} + while(1 > 0) +} +--------------------- +l0: + +l3: + ret l1 + r(1) + r(0) + r(>) + r(1 > 0) + jt(l3) +l2: + read (Unit) +l1: + +===================== diff --git a/idea/testData/cfg/OnlyWhileInFunctionBody.jet b/idea/testData/cfg/OnlyWhileInFunctionBody.jet new file mode 100644 index 00000000000..2cbdf061634 --- /dev/null +++ b/idea/testData/cfg/OnlyWhileInFunctionBody.jet @@ -0,0 +1,10 @@ +fun main() { + while(1 > 0) { + 2 + } +} + +fun dowhile() { + do {return} + while(1 > 0) +}