Regression from 2.0 to `version-2-2`/`devel` in `template` overload resolution with generics
### Description

```nim
template g(h: typedesc): untyped = {.error: "2.0 doesn't hit".}
type
  S[Y] = array[Y.g, int]
  N = object
template g(_: type N): untyped = 1
discard sizeof(S[N])
```

### Nim Version

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

git hash: 5935c3bfa9fec6505394867b23510eb5cbab3dbf
active boot switches: -d:release
```
```
Nim Compiler Version 2.0.9 [Linux: amd64]
Compiled at 2024-09-21
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 27381cc60213e19aa34664176bd358ca5e45bd5a
active boot switches: -d:release
```

Does not build:
```
Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-21
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 755307be61e4ee7b32c8354b2c303d04bdfc3a3e
active boot switches: -d:release
```
```
Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-21
Copyright (c) 2006-2024 by Andreas Rumpf

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

### Current Output

```text
/tmp/w.nim(3, 17) template/generic instantiation of `g` from here
/tmp/w.nim(1, 43) Error: 2.0 doesn't hit
```


### Expected Output

_No response_

### Known Workarounds

_No response_

### Additional Information

_No response_