From f1789cc465bcabc7afe0fe991df615246cfadb3b Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 1 Sep 2023 10:00:15 +0300 Subject: [PATCH] resolve local symbols in generic type call RHS (#22610) resolve local symbols in generic type call fixes #14509 --- compiler/semtypes.nim | 1 + tests/generics/m14509.nim | 16 ++++++++++++++++ tests/generics/t14509.nim | 4 ++++ 3 files changed, 21 insertions(+) create mode 100644 tests/generics/m14509.nim create mode 100644 tests/generics/t14509.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 8e304288b6d1..b469c69fbfb7 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -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) diff --git a/tests/generics/m14509.nim b/tests/generics/m14509.nim new file mode 100644 index 000000000000..cabc4f308b74 --- /dev/null +++ b/tests/generics/m14509.nim @@ -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) diff --git a/tests/generics/t14509.nim b/tests/generics/t14509.nim new file mode 100644 index 000000000000..ef3143ee4f1b --- /dev/null +++ b/tests/generics/t14509.nim @@ -0,0 +1,4 @@ +import m14509 + +var v: VecIntrin[4, float32] +doAssert $v == "[0.0, 0.0, 0.0, 0.0]"