source: tests/poly-self-cycle.cfa@ 119889f

Last change on this file since 119889f was 594671a, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Erase dtype types when they are encountered. Waiting to a use means that you may mutate your parent node and the changes are lost. Fixes 304.

  • Property mode set to 100644
File size: 678 bytes
Line 
1// Make sure that self references in polymorphic types do not cause issues.
2
3forall(T)
4struct TreeNodeO {
5 T data;
6 TreeNodeO(T) * left;
7 TreeNodeO(T) * right;
8};
9
10forall(T &)
11struct TreeNodeD {
12 T * data;
13 TreeNodeD(T) * left;
14 TreeNodeD(T) * right;
15};
16
17// Instantiate the two types in different ways.
18forall(U)
19void tree_node(TreeNodeO(U) & this) {
20 TreeNodeO(U) local;
21 local.left = &this;
22}
23
24forall(U)
25void tree_node(TreeNodeD(U) & this) {
26 TreeNodeD(U) local;
27 local.left = &this;
28}
29
30int main() {
31 TreeNodeO(int) node0;
32 tree_node(node0);
33 TreeNodeD(int) node1;
34 tree_node(node1);
35
36 // There is nothing interesting to print, so just print some noise.
37 printf("done!\n");
38}
Note: See TracBrowser for help on using the repository browser.