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

Errornous macro interactions with proc that takes a proc #9488

Open alaviss opened 6 years ago

alaviss commented 6 years ago

Sorry, I can't think of any meaningful summary for this bug

Example

import macros

proc take(x: proc(): bool) = discard

macro triggerBug(updId: bool): untyped =
  assert updId.boolVal

  proc filt(): bool = updId.boolVal

  take filt # Remove this line and everything works

triggerBug true

Current Output

Hint: used config file '/etc/nim/nim.cfg' [Conf]
Hint: system [Processing]
Hint: test [Processing]
Hint: macros [Processing]
stack trace: (most recent call last)
test.nim(6)              triggerBug
../usr/lib/nim/system.nim(3899) failedAssertImpl
../usr/lib/nim/system.nim(3892) raiseAssert
../usr/lib/nim/system.nim(2939) sysFatal
test.nim(12, 12) template/generic instantiation of `triggerBug` from here
../usr/lib/nim/system.nim(2939, 7) Error: unhandled exception: /tmp/test.nim(6, 10) `updId.boolVal`

Expected Output

Compiles successfully

Nim Version

Nim Compiler Version 0.19.1 [Linux: amd64]
Compiled at 2018-10-24
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: 3ee53a7c8ed31f41fb0abe0f4f051f5a66559467
active boot switches: -d:release -d:nativeStackTrace
zah commented 6 years ago

I'm pretty sure this is a duplicate of https://github.com/nim-lang/Nim/issues/9509

disruptek commented 4 years ago

Still present, as is #9509.

Nim Compiler Version 1.3.5 [Linux: amd64]
Compiled at 2020-08-05
Copyright (c) 2006-2020 by Andreas Rumpf

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