(module main)

(struct Point
  (x i32)
  (y i32))

(fn make_point ((x i32) (y i32)) -> Point
  (Point (x x) (y y)))

(fn point_x ((p Point)) -> i32
  (. p x))

(fn point_sum ((p Point)) -> i32
  (+ (. p x) (. p y)))

(fn local_point_sum () -> i32
  (let p Point (make_point 20 22))
  (point_sum p))

(test "struct local value flow"
  (= (local_point_sum) 42))

(test "struct parameter value flow"
  (= (point_x (make_point 7 9)) 7))

(test "stored struct field access"
  (let p Point (make_point 3 4))
  (= (. p y) 4))

(fn main () -> i32
  (local_point_sum))
