nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.22k stars 1.46k forks source link

regression from 2.0.4 to 2.0.6 cannot instantiate: 'SomeInteger' in return type #23730

Closed daniel-j closed 1 week ago

daniel-j commented 1 week ago

Description

When using a static parameter as right hand side argument to a function like shl (which takes a SomeInteger as 2nd argument) the Nim compiler throws an error. This is a regression I noticed when upgrading to Nim 2.0.6.

Test code:

proc test(M: static[int]): array[1 shl M, int] = discard
echo len(test(3))

Nim Version

Nim Compiler Version 2.0.6 [Linux: amd64] Compiled at 2024-06-17 Copyright (c) 2006-2023 by Andreas Rumpf

git hash: c00e8e71e0c8465b5a5257c76c674b803273b222 active boot switches: -d:release

Current Output

/usercode/in.nim(1, 36) template/generic instantiation of `shl` from here
/playground/nim/lib/system/arithmetics.nim(158, 21) Error: cannot instantiate: 'SomeInteger'

Expected Output

8

Possible Solution

No response

Additional Information

No response

metagn commented 1 week ago

Culprit is #23188, we check for generic parameters that are instantiated with unresolved statics, but in this case the parameter getting instantiated is only matching that it is int, not the actual static value. I am hoping that checking that the matched type is tyStatic is enough to deal with this.