From 934bf390297dc216d9a2203f342907ccabe468c4 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 13 Jun 2026 20:21:39 +0200 Subject: [PATCH] tests: add openSym dot-RHS regression test Tests the fix in 7148ae347: the RHS of a dot expression wrapped in nkOpenSym by the generic prepass must use the captured symbol when nothing is injected, while an injected symbol still overrides it. Co-Authored-By: Claude Opus 4.8 --- tests/generics/mopensymdot.nim | 18 ++++++++++++++++++ tests/generics/topensymdot.nim | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/generics/mopensymdot.nim create mode 100644 tests/generics/topensymdot.nim diff --git a/tests/generics/mopensymdot.nim b/tests/generics/mopensymdot.nim new file mode 100644 index 0000000000..c06766920d --- /dev/null +++ b/tests/generics/mopensymdot.nim @@ -0,0 +1,18 @@ +{.experimental: "openSym".} + +import std/hashes + +template maxHash(t): untyped = high(t).Hash + +template implCaptured() {.dirty.} = + result = maxHash(t) + +template implInjected() {.dirty.} = + type Hash = uint8 + result = high(t).Hash + +proc usesCaptured*[T](t: T): auto = + implCaptured() + +proc usesInjected*[T](t: T): auto = + implInjected() diff --git a/tests/generics/topensymdot.nim b/tests/generics/topensymdot.nim new file mode 100644 index 0000000000..3753041542 --- /dev/null +++ b/tests/generics/topensymdot.nim @@ -0,0 +1,12 @@ +# the RHS of a dot expression can be wrapped in `nkOpenSym` by the generic +# prepass (e.g. a `x.T` type conversion expanded from a dirty template): +# the captured symbol (`hashes.Hash`, not in scope here) must be used when +# nothing is injected, while a symbol injected during instantiation still +# overrides it + +{.experimental: "openSym".} + +import mopensymdot + +doAssert sizeof(usesCaptured(@[1, 2, 3])) == sizeof(int) # hashes.Hash +doAssert sizeof(usesInjected(@[1, 2, 3])) == 1 # injected uint8