Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strengthen taddr.nim: add test case for #14578; reference other issues; test cpp #15960

Merged
merged 2 commits into from
Nov 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions tests/js/taddr.nim → tests/misc/taddr.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
discard """
targets: "c js"
targets: "c cpp js"
matrix: "; -d:release"
"""

type T = object
Expand Down Expand Up @@ -79,7 +80,7 @@ someGlobalPtr[] = 10
doAssert(someGlobal == 10)

block:
# issue #14576
# bug #14576
# lots of these used to give: Error: internal error: genAddr: 2
proc byLent[T](a: T): lent T = a
proc byPtr[T](a: T): ptr T = a.unsafeAddr
Expand All @@ -89,24 +90,21 @@ block:
let (x,y) = byLent(a)
doAssert (x,y) == a

block:
when defined(c) and defined(release):
# bug; pending https://github.com/nim-lang/Nim/issues/14578
discard
else:
let a = 10
doAssert byLent(a) == 10
let a2 = byLent(a)
doAssert a2 == 10
block: # (with -d:release) bug #14578
let a = 10
doAssert byLent(a) == 10
let a2 = byLent(a)
doAssert a2 == 10

block:
let a = [11,12]
doAssert byLent(a) == [11,12]
when not defined(cpp): # pending bug #15958
let a = [11,12]
doAssert byLent(a) == [11,12]
let a2 = (11,)
doAssert byLent(a2) == (11,)

block:
when defined(c) and defined(release):
when (defined(c) or defined(cpp)) and defined(release):
discard # probably not a bug since optimizer is free to pass by value, and `unsafeAddr` is used
else:
var a = @[12]
Expand Down Expand Up @@ -134,6 +132,6 @@ block:
bar(a2).inc
doAssert a2 == 13

block: # xxx: bug this doesn't work
block: # pending bug #15959
when false:
proc byLent2[T](a: T): lent type(a[0]) = a[0]