Identifier exported as typename in one module and `template` in another can't be used in `template`
### Description

`c.nim`:
```nim
type K* = object
```

`s.nim`:
```nim
import ./c
export c
template K*(kind: static int): auto = typedesc[c.K]
template B*(kind: static int): auto = typedesc[c.K]
```

`j.nim`
```nim
import ./s
discard default(B(0))       # compiles
discard default(s.B(0))     # compiles
discard default(K(0))       # compiles
template r() =
  discard default(B(0))     # compiles
  discard default(s.B(0))   # compiles
  discard default(K(0))     # does not compile
```

### Nim Version

```
Nim Compiler Version 2.0.10 [Linux: amd64]
Compiled at 2024-07-27
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 92e505577e8b6b9214b6fcdd7fe1b0e9a244023b
active boot switches: -d:release
```

```
Nim Compiler Version 2.1.9 [Linux: amd64]
Compiled at 2024-07-27
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 39629a1adcbcc822508acc3983f444328f90dd85
active boot switches: -d:release
```

### Current Output

```text
j.nim(8, 19) Error: ambiguous identifier: 'K' -- use one of the following:
  c.K: K
  s.K: template (kind: static[int]): auto
```


### Expected Output

```text
If B(0), s.B(0), and K(0) work outside the template, and B(0) and s.B(0) work inside the template, K(0) also works inside the template.
```


### Possible Solution

_No response_

### Additional Information

Related to https://github.com/nim-lang/Nim/issues/23893 and `c.nim` and `s.nim` in both issues are identical.

In particular, as a result of that issue, one cannot work around this issue that readily in templates because by adding that disambiguating module identifier, it hits that issue instead of this issue but still does not compile.