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

Commit 1ad7da8

Browse files
committed
1469 - warn when calling macros with spliced args
1 parent d254107 commit 1ad7da8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

008eval.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ Cell* reorderKeywordArgs(Cell* params, Cell* args) {
155155
addCons(curr, arg);
156156
continue;
157157
}
158+
RAISE << "calling macros with splice can have subtle effects (http://arclanguage.org/item?id=15659)" << endl;
158159
Cell* newLimb = unsplice(arg);
159160
setCdr(curr, newLimb);
160161
rmref(newLimb);
@@ -167,6 +168,8 @@ Cell* reorderKeywordArgs(Cell* params, Cell* args) {
167168
Cell* result = unsplice(car(args));
168169
if (result == nil)
169170
return evalArgs(params, cdr(args));
171+
if (isCons(params) ? isQuoted(car(params)) : isQuoted(params))
172+
RAISE << "calling macros with splice can have subtle effects (http://arclanguage.org/item?id=15659)" << endl;
170173
Cell* curr = result;
171174
for (; cdr(curr) != nil; curr=cdr(curr))
172175
params=cdr(params); // don't eval spliced args again, even if param is unquoted

008eval.test.cc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,24 @@ void test_evalArgs_handles_quoted_rest_param() {
8888
endDynamicScope("a");
8989
}
9090

91-
void test_evalArgs_handles_spliced_vararg_arg() {
91+
void test_evalArgs_handles_spliced_arg_for_vararg_param() {
92+
newDynamicScope("a", newNum(3));
93+
newDynamicScope("b", newCons(newNum(4), newCons(newNum(5), nil)));
94+
Cell* params = read(stream("x"));
95+
Cell* args = read(stream("(a @b)"));
96+
Cell* evaldArgs = evalArgs(params, args);
97+
checkEq(car(evaldArgs), newNum(3));
98+
checkEq(car(cdr(evaldArgs)), newNum(4));
99+
checkEq(car(cdr(cdr(evaldArgs))), newNum(5));
100+
checkEq(cdr(cdr(cdr(evaldArgs))), nil);
101+
rmref(evaldArgs);
102+
rmref(args);
103+
rmref(params);
104+
endDynamicScope("b");
105+
endDynamicScope("a");
106+
}
107+
108+
void test_evalArgs_handles_spliced_arg_for_quoted_vararg_param() {
92109
newDynamicScope("a", newNum(3));
93110
newDynamicScope("b", newCons(newNum(4), newCons(newNum(5), nil)));
94111
Cell* params = read(stream("'x"));
@@ -103,6 +120,8 @@ void test_evalArgs_handles_spliced_vararg_arg() {
103120
rmref(params);
104121
endDynamicScope("b");
105122
endDynamicScope("a");
123+
checkEq(errorCount, 1); // raised warning
124+
errorCount = 0;
106125
}
107126

108127
void test_evalArgs_handles_spliced_arg() {

0 commit comments

Comments
 (0)