Files
Nim/tests/generics/t6137.nim
metagn e8092a5470 delay resolved procvar check for proc params + acknowledge unresolved statics (#23188)
fixes #23186

As explained in #23186, generics can transform `genericProc[int]` into a
call `` `[]`(genericProc, int) `` which causes a problem when
`genericProc` is resemmed, since it is not a resolved generic proc. `[]`
needs unresolved generic procs since `mArrGet` also handles explicit
generic instantiations, so delay the resolved generic proc check to
`semFinishOperands` which is intentionally not called for `mArrGet`.

The root issue for
[t6137](https://github.com/nim-lang/Nim/blob/devel/tests/generics/t6137.nim)
is also fixed (because this change breaks it otherwise), the compiler
doesn't consider the possibility that an assigned generic param can be
an unresolved static value (note the line `if t.kind == tyStatic: s.ast
= t.n` below the change in sigmatch), now it properly errors that it
couldn't instantiate it as it would for a type param. ~~The change in
semtypinst is just for symmetry with the code above it which also gives
a `cannot instantiate` error, it may or may not be necessary/correct.~~
Now removed, I don't think it was correct.

Still possible that this has unintended consequences.
2024-01-11 07:45:11 +01:00

29 lines
655 B
Nim

discard """
errormsg: "cannot instantiate: 'T'"
line: 19
"""
type
# simple vector of declared fixed length
vector[N : static[int]] = array[0..N-1, float]
proc `*`[T](x: float, a: vector[T]): vector[T] =
# multiplication by scalar
for ii in 0..high(a):
result[ii] = a[ii]*x
let
# define a vector of length 3
x: vector[3] = [1.0, 3.0, 5.0]
proc vectFunc[T](x: vector[T]): vector[T] =
# Define a vector function
result = 2.0*x
proc passVectFunction[T](g: proc(x: vector[T]): vector[T], x: vector[T]): vector[T] =
# pass a vector function as input in another procedure
result = g(x)
let
xNew = passVectFunction(vectFunc,x)