Skip to content

Commit 8375c30

Browse files
authored
Add a future for a case where I expect a lifetime error (#27071)
Adds a .future test for issue #27072. I ran into this case when writing about the lifetime checker. Test change only, not reviewed.
2 parents 6d468c3 + e3b4362 commit 8375c30

5 files changed

+34
-0
lines changed

test/classes/delete-free/lifetimes/return-ref-to-owned-local.bad

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Note: I was expecting a lifetime error for this code
2+
// but it compiles without error.
3+
4+
class C { var x: int; }
5+
6+
proc getRefToVal() ref {
7+
// allocate a class instance on the heap containing an integer field
8+
var instance = new owned C(0);
9+
10+
// create a reference the field 'x' on the heap
11+
ref refToVal = instance.x;
12+
13+
// return the reference
14+
// note: the class instance is freed here before return!
15+
return refToVal;
16+
}
17+
18+
proc main() {
19+
// create a reference the field 'x' on the heap
20+
ref refToVal = getRefToVal();
21+
22+
refToVal = 42;
23+
24+
// do other heap operations to make heap corruption more visible
25+
{
26+
var x = new owned C(2);
27+
var y = new owned C(3);
28+
}
29+
30+
writeln(refToVal);
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error message: missing lifetime checking error
2+
#27072
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some error about refToVal referring to something local

test/classes/delete-free/lifetimes/return-ref-to-owned-local.noexec

Whitespace-only changes.

0 commit comments

Comments
 (0)