mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-14 23:53:47 +00:00
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:
18
tests/generics/mopensymdot.nim
Normal file
18
tests/generics/mopensymdot.nim
Normal 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()
|
||||
12
tests/generics/topensymdot.nim
Normal file
12
tests/generics/topensymdot.nim
Normal 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
|
||||
Reference in New Issue
Block a user