Only restore parent context's \@ value if it had one defined (#1366)

This way, if a child context initializes `\@`, the parent won't
reset it. And if the child context did not initialize `\@`,
then resetting it would be redundant.
This commit is contained in:
Sylvie
2024-03-21 19:53:49 -04:00
committed by GitHub
parent 0f772932a5
commit f792580816
7 changed files with 108 additions and 5 deletions

View File

@@ -9,6 +9,7 @@
#include <inttypes.h>
#include <new>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string_view>
@@ -207,20 +208,23 @@ bool yywrap() {
return true;
}
Context oldContext = contextStack.top();
Context oldContext = std::move(contextStack.top());
contextStack.pop();
lexer_CleanupState(oldContext.lexerState);
// Restore args if a macro (not REPT) saved them
if (oldContext.fileInfo->type == NODE_MACRO)
macro_UseNewArgs(contextStack.top().macroArgs);
// Restore the `\@` value if the old context was supposed to define one
// (i.e. it either is a macro or REPT, or it initialized `\@` for its parent)
if (oldContext.fileInfo->type == NODE_REPT || oldContext.fileInfo->type == NODE_MACRO
|| contextStack.top().uniqueID > 0)
macro_SetUniqueID(contextStack.top().uniqueID);
// Free the file stack node
if (!oldContext.fileInfo->referenced)
delete oldContext.fileInfo;
lexer_SetState(&contextStack.top().lexerState);
macro_SetUniqueID(contextStack.top().uniqueID);
return false;
}