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 <noreply@anthropic.com>
This commit is contained in:
Araq
2026-06-13 20:21:39 +02:00
parent 37d6ea691d
commit 934bf39029
2 changed files with 30 additions and 0 deletions

View File

@@ -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()

View File

@@ -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