Skip to content

Commit 044ac99

Browse files
committed
feat(tests): adding more failing tests for macros
1 parent 09c2ff2 commit 044ac99

12 files changed

+39
-4
lines changed

src/arkreactor/Compiler/Macros/Processor.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,28 +210,30 @@ namespace Ark::internal
210210

211211
void MacroProcessor::checkMacroArgCountEq(const Node& node, std::size_t expected, const std::string& name, const std::string& kind)
212212
{
213-
const std::size_t argcount = node.constList().size();
213+
const std::size_t argcount = node.constList().size() - 1;
214214
if (argcount != expected + 1)
215215
throwMacroProcessingError(
216216
fmt::format(
217-
"Interpreting a `{}'{} with {} arguments, expected {}.",
217+
"Interpreting a `{}'{} with {} argument{}, expected {}.",
218218
name,
219219
kind.empty() ? kind : " " + kind,
220220
argcount,
221+
argcount > 1 ? "s" : "",
221222
expected),
222223
node);
223224
}
224225

225226
void MacroProcessor::checkMacroArgCountGe(const Node& node, std::size_t expected, const std::string& name, const std::string& kind)
226227
{
227-
const std::size_t argcount = node.constList().size();
228+
const std::size_t argcount = node.constList().size() - 1;
228229
if (argcount < expected + 1)
229230
throwMacroProcessingError(
230231
fmt::format(
231-
"Interpreting a `{}'{} with {} arguments, expected at least {}.",
232+
"Interpreting a `{}'{} with {} argument{}, expected at least {}.",
232233
name,
233234
kind.empty() ? kind : " " + kind,
234235
argcount,
236+
argcount > 1 ? "s" : "",
235237
expected),
236238
node);
237239
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(import package.builtin__list)
2+
3+
(print (reverse))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1 | (import package.builtin__list)
2+
2 |
3+
3 | (print (reverse))
4+
| ^~~~~~~
5+
4 |
6+
Symbol `reverse' was resolved to `builtin__list:reverse', which is also a builtin name. Either the symbol or the package it's in needs to be renamed to avoid conflicting with the builtin.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
($argcount 1)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
1 | ($argcount 1)
2+
| │ └─ error
3+
| │
4+
| └─ macro expansion started here
5+
2 |
6+
When trying to apply `$argcount', got a Number instead of a Symbol or Function
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
($if (= 1) ())
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 | ($if (= 1) ())
2+
| ^~~~~
3+
2 |
4+
Interpreting a `=' condition with 1 argument, expected 2.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(macro a (+ 1))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 | (macro a (+ 1))
2+
| ^~~~~
3+
2 |
4+
Interpreting a `+' operator with 1 argument, expected at least 2.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
($undef a b)

0 commit comments

Comments
 (0)