Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

currentSourcePath not returning the correct module name #6925

Open
ghost opened this issue Dec 14, 2017 · 1 comment
Open

currentSourcePath not returning the correct module name #6925

ghost opened this issue Dec 14, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Dec 14, 2017

Slightly modifying the sample code from documentation:

# simple.nim
import strutils

template testException*(exception, code: typed): untyped =
  try:
    let pos = currentSourcePath()
    discard(code)
    echo "Test failure at $1 with '$2'" % [pos, astToStr(code)]
    assert false, "A test expecting failure succeeded?"
  except exception:
    discard
# bug.nim
import simple

proc tester(pos: int): int =
  let
    a = @[1, 2, 3]
  result = a[pos]

when isMainModule:
  testException(IndexError, tester(30))
  testException(IndexError, tester(1))
  # --> Test failure at simple.nim with 'tester(1)'

One would expect to get the name of the module that is "main" not the imported one.

@ghost
Copy link
Author

ghost commented Dec 14, 2017

Replacing currentSourcePath with instantiationInfo(-1, true).filename fixes it.

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

No branches or pull requests

0 participants