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

ignore uninstantiated static on match to base type [backport:2.0] #23731

Closed metagn closed 1 week ago

metagn commented 1 week ago

fixes #23730

Since #23188 the compiler errors when matching a type variable to an uninstantiated static value. However sometimes an uninstantiated static value is given even when only a type match is being performed to the base type of the static type, in the given issue this case is:

proc foo[T: SomeInteger](x: T): int = int(x)
proc bar(x: static int): array[foo(x), int] = discard
discard bar(123)

To deal with this issue we only error when matching against a type variable constrained to static.

Not sure if the q.typ.kind == tyGenericParam and q.typ.genericConstraint == tyStatic check is necessary, the code above for deciding whether the variable becomes skConst doesn't use it.

github-actions[bot] commented 1 week ago

Thanks for your hard work on this PR! The lines below are statistics of the Nim compiler built from 128090c593df557c9e7c17e966a735312986a496

Hint: mm: orc; opt: speed; options: -d:release 178820 lines; 8.491s; 664.246MiB peakmem