Make expandMacro show private fields (#24522)

Was debugging with `--expandMacro` and noticed that private fields
weren't exported.
Passes extra flags to the renderer to make them be shown

(cherry picked from commit f80ce139d5)
This commit is contained in:
Jake Leahy
2024-12-18 04:17:04 +11:00
committed by narimiran
parent 0823b9d177
commit 09835a1d9e
2 changed files with 11 additions and 3 deletions

View File

@@ -526,7 +526,9 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
if efNoSemCheck notin flags:
result = semAfterMacroCall(c, n, result, sym, flags, expectedType)
if c.config.macrosToExpand.hasKey(sym.name.s):
message(c.config, nOrig.info, hintExpandMacro, renderTree(result))
message(c.config, nOrig.info, hintExpandMacro, renderTree(result, {
renderNonExportedFields, renderDocComments, renderNoComments
}))
result = wrapInComesFrom(nOrig.info, sym, result)
popInfoContext(c.config)

View File

@@ -1,8 +1,11 @@
discard """
cmd: "nim c --expandMacro:foo $file"
nimout: '''texpandmacro.nim(17, 1) Hint: expanded macro:
nimout: '''texpandmacro.nim(20, 1) Hint: expanded macro:
echo ["injected echo"]
var x = 4 [ExpandMacro]
var x = 4
type
Hello = object
private: string [ExpandMacro]
'''
output: '''injected echo'''
"""
@@ -16,3 +19,6 @@ macro foo(x: untyped): untyped =
foo:
var x = 4
type
Hello = object
private: string