Skip to content

Keep pretty-printer character variable local - #22

Open
dajiaohuang wants to merge 1 commit into
andremm:mainfrom
dajiaohuang:fix-pretty-printer-global-char
Open

dajiaohuang wants to merge 1 commit into
andremm:mainfrom
dajiaohuang:fix-pretty-printer-global-char

Conversation

@dajiaohuang

Copy link
Copy Markdown

Calling the documented pp.tostring API on an AST containing a string assigns each byte to the global char, overwriting a caller's existing value or creating a new global.

Make the character variable local to the loop. Adds a standalone pretty-printer regression, also invoked by test.lua, checking both an existing global sentinel and an absent global while preserving output.

Validation: the regression fails on the original implementation and passes with this fix under isolated embedded Lua 5.1, 5.3 and 5.4 runtimes (Lupa). Fixtures are self-created ASTs only. Native Lua was not on PATH and LPegLabel was unavailable in that isolated environment, so the full parser/luacov suite and the complete CI runtime matrix were not run. No user code or real applications were executed.

Comment thread test.lua
@@ -1,3 +1,5 @@
dofile("test-pp.lua")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to move this to the end of the file. Perhaps before the last OK print and maybe add a print saying you are testing the pretty printer.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to add the pretty printer test code at the end of this test file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants