From bb8864c34e1b41ce987b7a5f7c4b3a78136d2eed Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 12 Sep 2012 11:04:29 +0200 Subject: [PATCH] fix SOE in groovy control flow building (EA-39132,EA-39133) --- .../controlFlow/impl/ControlFlowBuilder.java | 18 +++++++++++------- .../groovy/lang/GroovyHighlightingTest.groovy | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) 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 e67018a2484f..e91bade429cd 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 @@ -382,12 +382,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { addNodeAndCheckPending(throwInstruction); interruptFlow(); - final PsiType type = RecursionManager.doPreventingRecursion(exception, true, new NullableComputable() { - @Override - public PsiType compute() { - return exception.getNominalType(); - } - }); + final PsiType type = getNominalTypeNoRecursion(exception); if (type != null) { ExceptionInfo info = findCatch(type); if (info != null) { @@ -402,6 +397,15 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { } } + private static PsiType getNominalTypeNoRecursion(final GrExpression exception) { + return RecursionManager.doPreventingRecursion(exception, true, new NullableComputable() { + @Override + public PsiType compute() { + return exception.getNominalType(); + } + }); + } + private void interruptFlow() { myHead = null; } @@ -924,7 +928,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor { final GrExpression condition = statement.getCondition(); if (!(condition instanceof GrReferenceExpression)) return false; - PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(condition.getNominalType()); + PsiType type = TypesUtil.unboxPrimitiveTypeWrapper(getNominalTypeNoRecursion(condition)); if (type == null) return false; if (type instanceof PsiPrimitiveType) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy index 0b17ef7b0f0e..49e27e17f8d4 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.groovy @@ -1419,4 +1419,19 @@ class X { testHighlighting('''\ def (a, b) = [a, a]''') } + + public void testSwitchInLoopNoSoe() { + testHighlighting(''' +def foo(File f) { + while (true) { + switch (f.name) { + case 'foo': f = new File('bar') + } + if (f) { + return + } + } +}''') + + } } \ No newline at end of file