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.55k stars 1.47k forks source link

Wrong stack trace when exception is raised in template #23620

Open simonkrauter opened 5 months ago

simonkrauter commented 5 months ago

Description

I found a case, where getStackTrace() returns the line number of the raise statement inside the template definition, instead of the line number of the template instantiation.

Test program:

type Severity = enum
  fatal
  regular

template raiseError*(severity: Severity) =
  if severity == fatal:
    raise newException(Defect, "error")

proc main() =
  try:
    raiseError(fatal)
  except:
    echo getCurrentException().getStackTrace()

main()

Note: Without the ìf statement it works correct.

Nim Version

Nim Compiler Version 2.0.4 [Linux: amd64] Compiled at 2024-03-28 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: b47747d31844c6bd9af4322efe55e24fefea544c active boot switches: -d:release

Current Output

main.nim(7)              main

Expected Output

main.nim(11)              main

Possible Solution

No response

Additional Information

No response

rockcavera commented 5 months ago

@simonkrauter see this: https://nim-lang.org/docs/manual.html#pragmas-line-pragma