resolve local symbols in generic type call RHS (#22610)

resolve local symbols in generic type call

fixes #14509
This commit is contained in:
metagn
2023-09-01 10:00:15 +03:00
committed by GitHub
parent 53d9fb259f
commit f1789cc465
3 changed files with 21 additions and 0 deletions

View File

@@ -1995,6 +1995,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
result = semTypeExpr(c, n[1], prev)
else:
if c.inGenericContext > 0 and n.kind == nkCall:
let n = semGenericStmt(c, n)
result = makeTypeFromExpr(c, n.copyTree)
else:
result = semTypeExpr(c, n, prev)

16
tests/generics/m14509.nim Normal file
View File

@@ -0,0 +1,16 @@
import macros
type float32x4 = array[4, float32]
type float32x8 = array[8, float32]
{.experimental: "dynamicBindSym".}
macro dispatch(N: static int, T: type SomeNumber): untyped =
let BaseT = getTypeInst(T)[1]
result = bindSym($BaseT & "x" & $N)
type
VecIntrin*[N: static int, T: SomeNumber] = dispatch(N, T)
func `$`*[N, T](vec: VecIntrin[N, T]): string =
## Display a vector
$cast[array[N, T]](vec)

View File

@@ -0,0 +1,4 @@
import m14509
var v: VecIntrin[4, float32]
doAssert $v == "[0.0, 0.0, 0.0, 0.0]"