(module main)

(enum Color Red Blue Green)

(fn make_palette () -> (array Color 3)
  (array Color (Color.Red) (Color.Blue) (Color.Green)))

(fn echo_palette ((colors (array Color 3))) -> (array Color 3)
  colors)

(fn at ((colors (array Color 3)) (i i32)) -> Color
  (index colors i))

(fn local_pick () -> Color
  (let colors (array Color 3) (make_palette))
  (index colors 1))

(test "enum array immediate index"
  (= (index (array Color (Color.Red) (Color.Blue) (Color.Green)) 2) (Color.Green)))

(test "enum array local index"
  (= (local_pick) (Color.Blue)))

(test "enum array param return dynamic index"
  (= (at (echo_palette (make_palette)) 0) (Color.Red)))

(fn main () -> i32
  (match (at (make_palette) 1)
    ((Color.Blue)
      0)
    ((Color.Red)
      1)
    ((Color.Green)
      1)))
