diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java index e847b0bc611d..c368b4094d36 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/controlFlow/impl/ControlFlowBuilder.java @@ -15,6 +15,8 @@ */ package org.jetbrains.plugins.groovy.lang.psi.controlFlow.impl; +import com.intellij.diagnostic.LogMessageEx; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.NullableComputable; import com.intellij.openapi.util.Pair; @@ -62,10 +64,12 @@ import static org.jetbrains.plugins.groovy.lang.psi.controlFlow.ReadWriteVariabl * @author ven */ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { + private static final Logger LOG = Logger.getInstance(ControlFlowBuilder.class); private List myInstructions; private Deque myProcessingStack; private final PsiConstantEvaluationHelper myConstantEvaluator; + private GroovyPsiElement myScope; private static class ExceptionInfo { final GrCatchClause myClause; @@ -241,6 +245,8 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { myPending = new ArrayList>(); myInstructionNumber = 0; + myScope = scope; + startNode(null); if (scope instanceof GrClosableBlock) { buildFlowForClosure((GrClosableBlock)scope); @@ -1090,7 +1096,9 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { interruptFlow(); finishNode(finallyInstruction); - assert oldPending != null; + if (oldPending == null) { + error(); + } oldPending.addAll(pendingPostCalls); myPending = oldPending; } @@ -1104,6 +1112,13 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } } + private void error() { + PsiFile file = myScope.getContainingFile(); + String fileText = file != null ? file.getText() : null; + + LogMessageEx.error(LOG, "broken control flow for a scope", myScope.getText(), "\n------------------\n", fileText); + } + private AfterCallInstruction addCallNode(InstructionImpl finallyInstruction, GroovyPsiElement scopeWhenAdded, InstructionImpl src) { interruptFlow(); final CallInstruction call = new CallInstruction(finallyInstruction); @@ -1130,7 +1145,9 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { private void finishNode(InstructionImpl instruction) { final InstructionImpl popped = myProcessingStack.pop(); - assert instruction.equals(popped); + if (!instruction.equals(popped)) { + error(); + } } public void visitField(GrField field) {