Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/ccgexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,10 @@ proc expr(p: BProc, n: PNode, d: var TLoc) =
# echo renderTree(p.prc.ast, {renderIds})
internalError(p.config, n.info, "expr: param not init " & sym.name.s & "_" & $sym.id)
putLocIntoDest(p, d, sym.loc)
of skTemplate, skMacro:
# it is possible to get these kind of symbols if cgen was called from nifbackend.nim
# as symbols are lazily loaded including symbol kinds, cannot exclude them when loading Nif files
discard
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fix makes no sense to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do these symbol kinds enter the backend for IC? And how is simply ignoring them a valid strategy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

When encoding procs, templates or macros defined under top level block statements to Nif, they are written as sdef.
When loading the Nif file, they are loaded as symbol nodes without nkProcDef/nkTemplateDef/nkMacroDef nodes.
expr proc in ccgexprs.nim simply ignores nkTemplateDef/nkMacroDef nodes and nkProcDef with sfCompileTime flag.

I'm trying to fix this bug by encoding procs, templates and macros defined under top level block statements in the same way as ast inside sdef (write full structure).

else: internalError(p.config, n.info, "expr(" & $sym.kind & "); unknown symbol")
of nkNilLit:
if not isEmptyType(n.typ):
Expand Down
1 change: 1 addition & 0 deletions tests/ic/mmacros.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
macro exportedMacro*(x: untyped): untyped = x
7 changes: 7 additions & 0 deletions tests/ic/tmacros_import.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# test imported macros
import mmacros

block:
exportedMacro:
let x = 123
assert x == 123
20 changes: 20 additions & 0 deletions tests/ic/tmacros_local.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# test macros without import
macro test0(x: untyped): untyped = x

block:
var x = 0
test0:
x = 123
assert x == 123

# issue # 25610
block:
macro foo(u: untyped): untyped =
discard

macro bar(x: untyped): untyped = x

bar:
let x = 111

assert x == 111