From e91d0680f67a93a76e917c6f34235b008f638845 Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Thu, 21 Nov 2024 12:02:51 +0100 Subject: [PATCH] added test and fixed bugs that the test triggered --- .../library/lang/rascal/tests/basic/Functions.rsc | 11 +++++++++++ src/org/rascalmpl/semantics/dynamic/Statement.java | 13 +++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc index fec17b3fa7d..3e5d6930ff4 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc @@ -588,3 +588,14 @@ test bool innerAndOuterFunctionUseSameParameterName4(){ return outer("a") == 3; } + +test bool stackoverflow() { + int f(int i) = f(i); + + try { + f(1); + return false; + } + catch StackOverflow(): + return true; +} \ No newline at end of file diff --git a/src/org/rascalmpl/semantics/dynamic/Statement.java b/src/org/rascalmpl/semantics/dynamic/Statement.java index c3af803f3b2..cd859683c21 100644 --- a/src/org/rascalmpl/semantics/dynamic/Statement.java +++ b/src/org/rascalmpl/semantics/dynamic/Statement.java @@ -29,7 +29,6 @@ import org.rascalmpl.ast.Target; import org.rascalmpl.ast.Type; import org.rascalmpl.exceptions.RascalStackOverflowError; -import org.rascalmpl.exceptions.RuntimeExceptionFactory; import org.rascalmpl.interpreter.Accumulator; import org.rascalmpl.interpreter.AssignableEvaluator; import org.rascalmpl.interpreter.IEvaluator; @@ -943,7 +942,7 @@ static public Result evalStatementTry(IEvaluator> eval, o IValue eValue = e.getException(); boolean handled = false; -r + for (Catch c : handlers) { if (c.isDefault()) { res = c.getBody().interpret(eval); @@ -994,11 +993,13 @@ private static boolean isCatchStackOverflow(org.rascalmpl.ast.Expression pattern return isCatchStackOverflow(pattern.getPattern()); } else if (pattern.isCallOrTree()) { - return pattern.getArguments().isEmpty() && "StackOverflow".equals(Names.name(pattern.getName())); - } - else { - return false; + var called = pattern.getExpression(); + if (called.hasName()) { + return pattern.getArguments().isEmpty() && "StackOverflow".equals(Names.name(called.getName())); + } } + + return false; } }