forked from nim-works/nimskull
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
tests/lang_experimental/views/timmutable_borrow_from_first_parameter.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
discard """ | ||
description: ''' | ||
Ensure a view borrowing from the first parameter can be safely returned | ||
from a procedure. | ||
''' | ||
targets: c js vm | ||
knownIssue.js vm: "The first parameter isn't passed by reference" | ||
""" | ||
|
||
block direct_lent_view_primitive: | ||
# test borrowing from primitive-type parameter with a direct view | ||
proc test(x: int): lent int = | ||
x | ||
|
||
var x = 0 | ||
doAssert addr(test(x)) == addr(x) | ||
|
||
block object_lent_view_primitive: | ||
# test borrowing from primitive-type parameter with an indirect view | ||
type Object = object | ||
x: lent int | ||
|
||
proc test(x: int): Object = | ||
Object(x: x) | ||
|
||
var x = 0 | ||
doAssert addr(test(x).x) == addr(x) |