From 5eaf609e8108507da16729b1136ee02e554d49c6 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 16 Jun 2023 18:14:47 +0300 Subject: [PATCH] add tests to close #7223, close #11733 (#22111) add test to close #7223, close #11733 closes #7223, closes #11733, were fixed by #22076 --- tests/template/mdotcall.nim | 28 ++++++++++++++++++++++++++++ tests/template/mdotcall2.nim | 7 +++++++ tests/template/tdotcall.nim | 26 ++++++++++++++++++-------- 3 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 tests/template/mdotcall2.nim diff --git a/tests/template/mdotcall.nim b/tests/template/mdotcall.nim index 38a6ccae0da89..13dcbd82489ef 100644 --- a/tests/template/mdotcall.nim +++ b/tests/template/mdotcall.nim @@ -20,3 +20,31 @@ proc bar(a: string): string = template baz*(a: string): string = var b = a.bar() b + +# issue #7223 + +import mdotcall2 + +type + Bytes* = seq[byte] + + BytesRange* = object + bytes*: Bytes + ibegin*, iend*: int + +proc privateProc(r: BytesRange): int = r.ibegin + +template rangeBeginAddr*(r: BytesRange): pointer = + r.bytes.baseAddr.shift(r.privateProc) + +# issue #11733 + +type ObjA* = object + +proc foo2(o: var ObjA) = discard +proc bar2(o: var ObjA, arg: Natural) = discard + +template publicTemplateObjSyntax*(o: var ObjA, arg: Natural, doStuff: untyped) = + o.foo2() + doStuff + o.bar2(arg) diff --git a/tests/template/mdotcall2.nim b/tests/template/mdotcall2.nim new file mode 100644 index 0000000000000..e906ac9d69456 --- /dev/null +++ b/tests/template/mdotcall2.nim @@ -0,0 +1,7 @@ +# imported by mdotcall + +proc baseAddr*[T](x: openarray[T]): pointer = + cast[pointer](x) + +proc shift*(p: pointer, delta: int): pointer = + cast[pointer](cast[int](p) + delta) diff --git a/tests/template/tdotcall.nim b/tests/template/tdotcall.nim index abcbc8bd5a176..5fc991dd2dcb7 100644 --- a/tests/template/tdotcall.nim +++ b/tests/template/tdotcall.nim @@ -1,10 +1,20 @@ import mdotcall -# issue #20073 -works() -boom() - -# issue #7085 -doAssert baz("hello") == "hellobar" -doAssert baz"hello" == "hellobar" -doAssert "hello".baz == "hellobar" +block: # issue #20073 + works() + boom() + +block: # issue #7085 + doAssert baz("hello") == "hellobar" + doAssert baz"hello" == "hellobar" + doAssert "hello".baz == "hellobar" + +block: # issue #7223 + var r = BytesRange(bytes: @[1.byte, 2, 3], ibegin: 0, iend: 2) + var a = r.rangeBeginAddr + +block: # issue #11733 + var a: ObjA + var evaluated = false + a.publicTemplateObjSyntax(42): evaluated = true + doAssert evaluated