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

Injected symbol is not visible in generic procedure #15693

Open haxscramper opened 4 years ago

haxscramper commented 4 years ago

Identifier identifier in template is visible in regular code, but fails compilation with undeclared identifier error when used in generic procedure.

Example

template getSome(val: typed, injected: untyped): untyped =
  let injected = val

block:
  123.getSome(resVal)
  assert resVal == 123
  discard resVal

proc g[T](arg: T) =
  arg.getSome(resVal)
  assert resVal == arg # works fine!
  discard resVal # fails to compile

g(12)

Current Output

/usercode/in.nim(14, 11) Error: undeclared identifier: 'resVal'

Expected Output

No compilation errors

Compiler version

$ nim -v
Nim Compiler Version 1.4.0 [Linux: amd64]
Compiled at 2020-10-16
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: bdcd87afca238a0a7b2c70971827cf9172817b12
active boot switches: -d:release -d:danger
timotheecour commented 4 years ago

can you minimize to something that doesn't have any imports? also {.inject.} doesnt' seem needed since injected is a template argument, IIRC

might be a duplicate but I don't remember which issue