nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.54k stars 1.47k forks source link

Macro used as proc pragma meddles with proc filename #19061

Open Wh1teDuke opened 2 years ago

Wh1teDuke commented 2 years ago

Test

# p3.nim
import std/macros

macro p3*(this: untyped): untyped =
  result = this
  result[^1] = quote do:
    echo currentSourcePath()
    echo getStackTraceEntries()[^1].filename
    echo getFrame().filename
#--------------------------------------
# main.nim
import "p3"

proc p2 {.p3.} = discard
proc p1 = p2()
proc main = p1()
main()

Result

p3.nim

Expected

main.nim

As far as I'm concerned, there is no workaround for this situation.


>nim -v
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2021-10-24
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 62701cd3b92677c2014cf70b1cf5a5ba6e0468bf
active boot switches: -d:release -d:danger
metagn commented 3 weeks ago

Not sure if this is still a problem but you can use lineInfoObj