Skip to content

Commit

Permalink
Merge pull request #3181 from thehans/recur_limit
Browse files Browse the repository at this point in the history
Minimal fix for #3118  Tail recursion limit not working
  • Loading branch information
kintel authored Jan 4, 2020
2 parents 90969e4 + f025cea commit 552643c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,14 @@ FunctionCall::FunctionCall(Expression *expr, const AssignmentList &args, const L
*/
void FunctionCall::prepareTailCallContext(const std::shared_ptr<Context> context, std::shared_ptr<Context> tailCallContext, const AssignmentList &definition_arguments)
{
if (this->resolvedArguments.empty()) {
if (this->resolvedArguments.empty() && !this->arguments.empty()) {
// Figure out parameter names
ContextHandle<EvalContext> ec{Context::create<EvalContext>(context, this->arguments, this->loc)};
this->resolvedArguments = ec->resolveArguments(definition_arguments, {}, false);
}

// FIXME: evaluate defaultArguments in FunctionDefinition / UserFunction and pass to FunctionCall instead of definition_arguments ?
if (this->defaultArguments.empty() && !definition_arguments.empty()) {
// Assign default values for unspecified parameters
for (const auto &arg : definition_arguments) {
if (this->resolvedArguments.find(arg->name) == this->resolvedArguments.end()) {
Expand Down
4 changes: 4 additions & 0 deletions testdata/scad/issues/issue3118-recur-limit.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Issue #3118
// Verify recursion limit is reached when no arguments provided in call.
function sin(x) = sin();
echo(sin(30));
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ list(APPEND ECHO_FILES ${FUNCTION_FILES} ${MISC_FILES}
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/preview_variable.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/issues/issue1851-each-fail-on-scalar.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/issues/issue2342.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/issues/issue3118-recur-limit.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/function-scope.scad
)

Expand Down
3 changes: 3 additions & 0 deletions tests/regression/echotest/issue3118-recur-limit-expected.echo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ERROR: Recursion detected calling function 'sin' in file issue3118-recur-limit.scad, line 3
TRACE: called by 'sin', in file issue3118-recur-limit.scad, line 4.
TRACE: called by 'echo', in file issue3118-recur-limit.scad, line 4.

0 comments on commit 552643c

Please sign in to comment.