Skip to content

Commit

Permalink
add tests w/ current temporary lifetime behavior
Browse files Browse the repository at this point in the history
(for better or worse)
  • Loading branch information
nikomatsakis committed Mar 4, 2022
1 parent 7779749 commit 96a96d8
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dada_tests/specifier/temporary-lifetime/call-argument.dada
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Object(any data)

async fn main() {
any o = lease_me(Object(22)).data
#! RUN ERROR your lease to this object was cancelled
#
# What happens here:
# * the `Object(22)` is stored into a temporary that is dropped as soon
# as the call completes.
#
#! FIXME: This seems kind of annoying!

print(o).await
}

fn lease_me(leased p) {
p
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions dada_tests/specifier/temporary-lifetime/if-then-else-leased.dada
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Object(any data)

async fn main() {
any o = if true { Object(true).lease } else { Object(false).lease }
#! RUN ERROR your lease to this object was cancelled
#
# What happens here:
# * `Object(true).lease` is equivalent to `{ any o = Object(true); o.lease }`
# * that variable `o` is dropped as we exit the `if-then-else`

print(o).await
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Object(any data)

async fn main() {
# This is equivalent to `if { .. } else { .. }.lease`.
leased o = if true { Object(true) } else { Object(false) }
print(o).await #! OUTPUT Object\(true\)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leased Object(true)

0 comments on commit 96a96d8

Please sign in to comment.