fix SOE in groovy control flow building (EA-39132,EA-39133)

This commit is contained in:
peter
2012-09-12 11:36:29 +02:00
parent fbab25d386
commit bb8864c34e
2 changed files with 26 additions and 7 deletions
@@ -382,12 +382,7 @@ public class ControlFlowBuilder extends GroovyRecursiveElementVisitor {
addNodeAndCheckPending(throwInstruction);
interruptFlow();
final PsiType type = RecursionManager.doPreventingRecursion(exception, true, new NullableComputable<PsiType>() {
@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<PsiType>() {
@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) {
@@ -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
}
}
}''')
}
}