consider generic param type as typedesc in tuple type expressions (#25316)

fixes #25312

Tuple expressions `(a, b, c)` can be either types or values depending on
if their elements are typedescs or values, this is checked by checking
if the type of the element is `tyTypeDesc`. However when an
`skGenericParam` symbol is semchecked by `semSym` it is given its own
`tyGenericParam` type rather than a `tyTypeDesc` type, this seems to be
necessary for signatures to allow wildcard generic params passed to
static constrained generic params (tested in #25315). The reason
`semSym` is called is that `semGeneric` for generic invocations calls
`matches` which sems its arguments like normal expressions.

To deal with this, an expression of type `tyGenericParam` and with a
`skGenericParam` sym is allowed as a type in the tuple expression. A
problem is that this might consider a value with a wildcard generic
param type as a type. But this is a very niche problem, and I'm not sure
how to check for this. `skGenericParam` symbols stay as idents when
semchecked so it can't be checked that the node is an `skGenericParam`
symbol. It could be checked that it's an ident but I don't know how
robust this is. And maybe there is another way to refer to a wildcard
generic param type instead of just its symbol, i.e. another kind of
node.

This also makes #5647 finally work but a test case for that can be added
after.

(cherry picked from commit 44d2472b08)
This commit is contained in:
metagn
2025-12-09 11:45:37 +03:00
committed by narimiran
parent 6c8ab9f898
commit c8556ef5df
2 changed files with 43 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
# issue #25312
import heapqueue
proc test1[T](test: (float, T)) = # Works
discard
proc test2[T](test: seq[(float, T)]) = # Works
discard
proc test3[T](test: HeapQueue[tuple[sqd: float, data: T]]) = # Works
discard
proc test4(test: HeapQueue[(float, float)]) = # Works
discard
type ExampleObj = object
a: string
b: seq[float]
proc test5(test: HeapQueue[(float, ExampleObj)]) = # Works
discard
proc failingTest[T](test: HeapQueue[(float, T)]) = # (Compile) Error: Mixing types and values in tuples is not allowed.
discard
proc failingTest2[T](test: HeapQueue[(T, float)]) = # (Compile) Error: Mixing types and values in tuples is not allowed.
discard
proc test6[T](test: HeapQueue[(T, T)]) = # works
discard
proc test7[T, U](test: HeapQueue[(T, U)]) = # works
discard