aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/methodown.zc
blob: 2d90f4b5ff5947e90209cb1e45b21f0312ba2b03 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
namespace;
include rt;

// a struct method can return an owned object: its header declares the .u return
struct Node { int v; }
struct Maker {
	static Node*.u make(int n) { Node* p = rt.new(Node); p.v = n; return u*p; }
}
Node*.u mk(int n) { Node* p = rt.new(Node); p.v = n; return u*p; }
int main() {
	Node*.u a = Maker.make(7);
	rt.put_n(a.v); rt.put_c(32);
	rt.free(d*a);
	Node*.u b = mk(9);
	rt.put_n(b.v); rt.put_c(10);
	rt.free(d*b);
	return 0;
}