Regression from v2.0.8 to v2.0.10/`version-2-0`/2.2/`devel`: `Error: request to generate code for .compileTime proc: $`
### Description

```nim
proc d(_: static[string]) = discard $0
proc m(_: static[string]) = d("")
iterator v(): int {.closure.} =
  template a(n: untyped) =
    when typeof(n) is void:
      n
    else:
      n
  a(m(""))
let _ = v
```

### Nim Version

Builds:
```
Nim Compiler Version 2.0.8 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf
active boot switches: -d:release
```

Does not build:
```
Nim Compiler Version 2.0.10 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: e941ee15be775fe3c46db1bed9b4f41c7dfb1334
active boot switches: -d:release
```

```
Nim Compiler Version 2.2.0 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 78983f1876726a49c69d65629ab433ea1310ece1
active boot switches: -d:release
```

```
Nim Compiler Version 2.2.1 [Linux: amd64]
Compiled at 2024-10-03
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: d6a71a10671b66ee4f5be09f99234b3d834e7fce
active boot switches: -d:release
```

### Current Output

```text
/tmp/h.nim(1, 37) Error: request to generate code for .compileTime proc: $
```


### Expected Output

_No response_

### Known Workarounds

_No response_

### Additional Information

_No response_