Regression with `mixin` and generics from 2.0.8 to `version-2-0`/`version-2-2`, fixed in `devel`
### Description

```nim
type
  K = distinct int
  M = object

proc p(e: auto, T: type): T =
  mixin p
  p(e, result)

proc p[T](r: M, g: T) =
  when g is object:
    mixin p
    discard p(r, K)
  else:
    {.error: "u".}

proc p(_: M, _: K | K) = discard
```

### Nim Version

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

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

`devel`:
```
Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2024 by Andreas Rumpf

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

Does not build:
`version-2-0`:
```
Nim Compiler Version 2.0.9 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2023 by Andreas Rumpf

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

`version-2-2`:
```
Nim Compiler Version 2.1.99 [Linux: amd64]
Compiled at 2024-09-23
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 755307be61e4ee7b32c8354b2c303d04bdfc3a3e
active boot switches: -d:release
```

### Current Output

```text
/tmp/v.nim(17, 10) template/generic instantiation of `p` from here
/tmp/v.nim(7, 4) template/generic instantiation of `p` from here
/tmp/v.nim(14, 12) Error: u
```


### Expected Output

_No response_

### Known Workarounds

_No response_

### Additional Information

Fixed in `devel`, so presumably there's something to backport from `devel` to `version 2-0`/`version-2-2`.