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