File tree Expand file tree Collapse file tree
java/latte/latte_umbrella Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ void push( @Free Object value) {
2828 }
2929
3030
31- public @ Free Node test ( @ Free Object value ) {
31+ public @ Shared Node test ( @ Free Object value ) {
3232 return new Node (value ,null );
3333 }
3434
Original file line number Diff line number Diff line change 1+
2+ import specification .Borrowed ;
3+ import specification .Free ;
4+ import specification .Unique ;
5+ import specification .Shared ;
6+
7+ public class MyStackFieldAssignMethod {
8+
9+ @ Unique Node root ;
10+
11+ public MyStack (@ Free Node root ) {
12+ this .root = root ;
13+ }
14+
15+ void push ( @ Free Object value ) {
16+ Node r ;
17+ Node n ;
18+
19+ r = this .root ; // save root in r
20+ this .root = null ; //nullify root
21+
22+
23+ this .root = test (null );
24+ // n = new Node(value, r); //create new root
25+ // this.root = n; //replace root
26+ }
27+
28+
29+ public @ Shared Node test ( @ Free Object value ) {
30+ return new Node (value ,null );
31+ }
32+
33+ }
34+
35+ /**
36+ * Node class for the stack example
37+ * Uses @Unique annotations to specify that the value and next fields are unique
38+ * in the scope of the Node class
39+ * @author catarina gamboa
40+ *
41+ */
42+ class Node {
43+
44+ @ Unique Object value ;
45+ @ Unique Node next ;
46+
47+ /**
48+ * Constructor for the Node class using @Free value and next nodes
49+ * @param value
50+ * @param next
51+ */
52+ public Node (@ Free Object value , @ Free Node next ) {
53+ this .value = value ;
54+ this .next = next ;
55+ }
56+ }
Original file line number Diff line number Diff line change @@ -127,6 +127,16 @@ public void testSmallestIncorrectExample(){
127127
128128 }
129129
130+ @ Test
131+ public void testMyStackFieldAssignMethod (){
132+ try {
133+ App .launcher ("src/test/examples/MyStackFieldAssignMethod.java" );
134+ } catch (Exception e ) {
135+ assertTrue (e instanceof LatteException );
136+ assertTrue (e .getMessage ().contains ("UNIQUE but got SHARED" ));
137+ }
138+ }
139+
130140
131141 @ Test
132142 public void testReachabilityUnitTest (){
You can’t perform that action at this time.
0 commit comments