From 9abbc6f1cad2a6ddac8339dc2eb3b202b0d94ae8 Mon Sep 17 00:00:00 2001 From: Jason Beetham Date: Fri, 28 Mar 2025 01:09:43 -0600 Subject: [PATCH] Fixes #66 by skipping over sink types in the sameType macro --- union.nimble | 2 +- union/typeutils.nim | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/union.nimble b/union.nimble index 0f2c3a4..ed60e2d 100644 --- a/union.nimble +++ b/union.nimble @@ -1,6 +1,6 @@ # Package -version = "0.2.0" +version = "0.2.1" author = "Leorize" description = "Anonymous unions in Nim" license = "MIT" diff --git a/union/typeutils.nim b/union/typeutils.nim index 8068635..5ab4e64 100644 --- a/union/typeutils.nim +++ b/union/typeutils.nim @@ -56,6 +56,13 @@ func newTypedesc*(n: NimNode): NimNode = ## Create a typedesc[n] nnkBracketExpr.newTree(bindSym"typedesc", copy(n)) + +proc skipSink(n: NimNode): NimNode = + if n.kind == nnkBracketExpr and n[0].eqIdent"sink": + n[1] + else: + n + func sameType*(a, b: NimNode): bool = ## A variant of sameType to workaround: ## @@ -63,6 +70,10 @@ func sameType*(a, b: NimNode): bool = ## ## * https://github.com/nim-lang/Nim/issues/19072 + let + a = a.skipSink() + b = b.skipSink() + # XXX: compiler bug workaround; see https://github.com/nim-lang/Nim/issues/18867 if macros.sameType(a, b) or macros.sameType(b, a): # XXX: compiler bug workaround; see https://github.com/nim-lang/Nim/issues/19072