This looks related to #2670. Consider the following example: ``` nim template someTempl(someConst: bool) = when someConst: var a : int if true: when not someConst: var a : int a = 5 someTempl(true) ``` ``` test.nim(9, 10) template/generic instantiation from here test.nim(7, 5) Error: expression 'a' has no type (or is ambiguous) ```