Restore blue-painting of macro arg expansions to prevent recursion

This commit is contained in:
Rangi42
2025-07-20 11:53:36 -04:00
parent cfe1f60e47
commit e3a5290dad
4 changed files with 16 additions and 0 deletions

View File

@@ -817,6 +817,11 @@ static int peek() {
shiftChar();
if (std::shared_ptr<std::string> str = readMacroArg(); str) {
beginExpansion(str, std::nullopt);
// Mark the entire macro arg expansion as "painted blue"
// so that macro args can't be recursive
// https://en.wikipedia.org/wiki/Painted_blue
lexerState->macroArgScanDistance += str->length();
}
} else if (c == '{' && !lexerState->disableInterpolation) {
// If character is an open brace, do symbol interpolation

View File

@@ -0,0 +1,6 @@
MACRO m
def x = (\1) * 2
println "{d:x}"
ENDM
m 5 ; prints 10
m \\2, 6 ; should not prints 12

View File

@@ -0,0 +1,3 @@
error: macro-arg-recursion.asm(6) -> macro-arg-recursion.asm::m(2):
Begun line continuation, but encountered character '2'
Assembly aborted with 1 error!

View File

@@ -0,0 +1,2 @@
10
4