add tests to close #7223, close #11733 (#22111)

add test to close #7223, close #11733

closes #7223, closes #11733, were fixed by #22076
This commit is contained in:
metagn
2023-06-16 18:14:47 +03:00
committed by GitHub
parent 77beb15214
commit 88388040db
3 changed files with 52 additions and 7 deletions

View File

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

View File

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

View File

@@ -1,10 +1,20 @@
import mdotcall
# issue #20073
works()
boom()
block: # issue #20073
works()
boom()
# issue #7085
doAssert baz("hello") == "hellobar"
doAssert baz"hello" == "hellobar"
doAssert "hello".baz == "hellobar"
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