import edu.rice.cs.mint.runtime.*;

public class SeparableSample3 {
    static int sfield = 0;
    int field = 0;
    SafeCode<Integer> cc, dd;
    public static separable SafeCode<Integer> getCodeOne() { return <| 1 |>; }
    public static separable int getOne() { return 1; }
    {
        cc = <| `(getCodeOne()) |>;
        dd = <| `(cc)+getOne() |>;
    }
    public static class IntPair {
        public int first;
        public int second;
        public static int boo;
        public Integer[] arr = new Integer[10];
        {
            int i = 4;
            i = 5;
            first = 0;
            this.first = 0;
            //     boo = 3; // not okay
            //      arr[0] = 5; // not okay
            //      this.boo = 1; // not okay
        }
        static {
            //     boo = 2; // not okay
        }
        public separable IntPair(int f, int s) {
            first = f; // okay, assignment to non-static this fields in ctor
            second = s;
            //     boo = 1; // not okay
            //     arr[0] = 1; // not okay
            arr = new Integer[10];
            this.first = f; // okay, assignment to non-static this fields in ctor
            //      this.boo = 1; // not okay
        }
    }
    public separable SafeCode<Integer> method(int i, IntPair p) {
        i = 2; // okay
        int j = i; // okay
        j = 3; // okay
        final int k = i;
        // sfield += 1; // not okay
        // field = 1; // not okay
        // p.first = 1; // not okay
        return <| k |>;
    }
    public void run() {
        IntPair p = new IntPair(0,0);
        SafeCode<Integer> c2 = <| 2 |>;
        Code<Integer> c = <|
            `(method(1, new IntPair(0,0))) +
            `c2 |>;
        System.out.println("c.run() = "+c.run()+" (expected: 4)");
        System.out.println(cc.run());
        System.out.println(dd.run());
    }
    public static void main (String [] args) {
        new SeparableSample3().run();
    }
}
