Skip to content
This repository has been archived by the owner on Jan 16, 2021. It is now read-only.

Commit

Permalink
1469 - warn when calling macros with spliced args
Browse files Browse the repository at this point in the history
  • Loading branch information
akkartik committed Feb 1, 2012
1 parent d254107 commit 1ad7da8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions 008eval.cc
Expand Up @@ -155,6 +155,7 @@ Cell* reorderKeywordArgs(Cell* params, Cell* args) {
addCons(curr, arg);
continue;
}
RAISE << "calling macros with splice can have subtle effects (http://arclanguage.org/item?id=15659)" << endl;
Cell* newLimb = unsplice(arg);
setCdr(curr, newLimb);
rmref(newLimb);
Expand All @@ -167,6 +168,8 @@ Cell* reorderKeywordArgs(Cell* params, Cell* args) {
Cell* result = unsplice(car(args));
if (result == nil)
return evalArgs(params, cdr(args));
if (isCons(params) ? isQuoted(car(params)) : isQuoted(params))
RAISE << "calling macros with splice can have subtle effects (http://arclanguage.org/item?id=15659)" << endl;
Cell* curr = result;
for (; cdr(curr) != nil; curr=cdr(curr))
params=cdr(params); // don't eval spliced args again, even if param is unquoted
Expand Down
21 changes: 20 additions & 1 deletion 008eval.test.cc
Expand Up @@ -88,7 +88,24 @@ void test_evalArgs_handles_quoted_rest_param() {
endDynamicScope("a");
}

void test_evalArgs_handles_spliced_vararg_arg() {
void test_evalArgs_handles_spliced_arg_for_vararg_param() {
newDynamicScope("a", newNum(3));
newDynamicScope("b", newCons(newNum(4), newCons(newNum(5), nil)));
Cell* params = read(stream("x"));
Cell* args = read(stream("(a @b)"));
Cell* evaldArgs = evalArgs(params, args);
checkEq(car(evaldArgs), newNum(3));
checkEq(car(cdr(evaldArgs)), newNum(4));
checkEq(car(cdr(cdr(evaldArgs))), newNum(5));
checkEq(cdr(cdr(cdr(evaldArgs))), nil);
rmref(evaldArgs);
rmref(args);
rmref(params);
endDynamicScope("b");
endDynamicScope("a");
}

void test_evalArgs_handles_spliced_arg_for_quoted_vararg_param() {
newDynamicScope("a", newNum(3));
newDynamicScope("b", newCons(newNum(4), newCons(newNum(5), nil)));
Cell* params = read(stream("'x"));
Expand All @@ -103,6 +120,8 @@ void test_evalArgs_handles_spliced_vararg_arg() {
rmref(params);
endDynamicScope("b");
endDynamicScope("a");
checkEq(errorCount, 1); // raised warning
errorCount = 0;
}

void test_evalArgs_handles_spliced_arg() {
Expand Down

0 comments on commit 1ad7da8

Please sign in to comment.