Cannot infer the value of static parameters in certain cases (regression 2.1.1 → 2.2.0)
### Description

The following program works correctly in Nim 2.1.1:

```nim
type Matrix[m, n: static int] = array[m * n, float]

func `[]`(A: Matrix, i, j: int): float =
  A[A.n * i + j]

func `[]`(A: var Matrix, i, j: int): var float =
  A[A.n * i + j]

func `*`[m, n, p: static int](A: Matrix[m, n], B: Matrix[n, p]): Matrix[m, p] =
  for i in 0 ..< m:
    for k in 0 ..< p:
      for j in 0 ..< n:
        result[i, k] += A[i, j] * B[j, k]

let A: Matrix[2, 2] = [-1, 1, 0, -1]
echo(A * A)
```

However, in Nim 2.2.0 it fails to compile with the error shown below.

### Nim Version

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

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

### Current Output

```text
Hint: used config file '/home/xigoi/.choosenim/toolchains/nim-2.2.0/config/nim.cfg' [Conf]
Hint: used config file '/home/xigoi/.choosenim/toolchains/nim-2.2.0/config/config.nims' [Conf]
Hint: used config file '/home/xigoi/.config/nim/nim.cfg' [Conf]
.....................................................................
/home/xigoi/sandbox/program.nim(16, 8) template/generic instantiation of `*` from here
/home/xigoi/.choosenim/toolchains/nim-2.2.0/lib/system/arithmetics.nim(10, 6) Error: cannot infer the value of the static param 'm'
```

### Expected Output

```text
[1.0, -2.0, 0.0, 1.0]
```

### Known Workarounds

_No response_

### Additional Information

_No response_