Skip to content

Commit

Permalink
resolve local symbols in generic type call RHS (#22610)
Browse files Browse the repository at this point in the history
resolve local symbols in generic type call

fixes #14509
  • Loading branch information
metagn committed Sep 1, 2023
1 parent 53d9fb2 commit f1789cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions tests/generics/m14509.nim
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions tests/generics/t14509.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import m14509

var v: VecIntrin[4, float32]
doAssert $v == "[0.0, 0.0, 0.0, 0.0]"

0 comments on commit f1789cc

Please sign in to comment.