new .redefine pragma for templates, warn on redefinition without it (#20211)
* test CI for template redefinitions * adapt asyncmacro * fix quote * fix again * try something else * revert * fix ioselectors_select, disable packages CI * adapt more tests & simplify * more * more * more * rename to redefine, warn on implicit redefinition * basic documentation [skip ci] * Update compiler/lineinfos.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
This commit is contained in:
parent
14656154ef
commit
d1d141b135
19 changed files with 85 additions and 25 deletions
|
|
@ -85,7 +85,9 @@ template onFailedAssert*(msg, code: untyped): untyped {.dirty.} =
|
|||
onFailedAssert(msg):
|
||||
raise (ref MyError)(msg: msg, lineinfo: instantiationInfo(-2))
|
||||
doAssertRaises(MyError): doAssert false
|
||||
template failedAssertImpl(msgIMPL: string): untyped {.dirty.} =
|
||||
when not defined(nimHasTemplateRedefinitionPragma):
|
||||
{.pragma: redefine.}
|
||||
template failedAssertImpl(msgIMPL: string): untyped {.dirty, redefine.} =
|
||||
let msg = msgIMPL
|
||||
code
|
||||
|
||||
|
|
@ -98,7 +100,7 @@ template doAssertRaises*(exception: typedesc, code: untyped) =
|
|||
var wrong = false
|
||||
const begin = "expected raising '" & astToStr(exception) & "', instead"
|
||||
const msgEnd = " by: " & astToStr(code)
|
||||
template raisedForeign = raiseAssert(begin & " raised foreign exception" & msgEnd)
|
||||
template raisedForeign {.gensym.} = raiseAssert(begin & " raised foreign exception" & msgEnd)
|
||||
when Exception is exception:
|
||||
try:
|
||||
if true:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue