Skip to content

Commit

Permalink
add test to close nim-lang#7223, close nim-lang#11733
Browse files Browse the repository at this point in the history
closes nim-lang#7223, closes nim-lang#11733, were fixed by nim-lang#22076
  • Loading branch information
metagn committed Jun 16, 2023
1 parent 0a19d78 commit b6ae893
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 8 deletions.
28 changes: 28 additions & 0 deletions tests/template/mdotcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
7 changes: 7 additions & 0 deletions tests/template/mdotcall2.nim
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 18 additions & 8 deletions tests/template/tdotcall.nim
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b6ae893

Please sign in to comment.