program main
  fn add_local(a: i32) -> i32
    local let one: i32
      int 1
    local var total: i32
      binary +
        var a
        var one
    set total
      binary +
        var total
        int 1
    var total
  fn keep_flag(flag: bool) -> bool
    local let local_flag: bool
      var flag
    var local_flag
  fn flip_flag(flag: bool) -> bool
    local var current: bool
      var flag
    set current
      if
        var current
        bool false
        bool true
    var current
  fn add_wide_local(base: i64) -> i64
    local var count: i64
      var base
    set count
      binary +
        var count
        i64 2
    var count
  fn add_ratio_local(base: f64) -> f64
    local var amount: f64
      var base
    set amount
      binary +
        var amount
        float 0.5
    var amount
  fn main() -> i32
    local var flag: bool
      bool false
    set flag
      call flip_flag
        var flag
    if
      var flag
      call add_local
        int 2
      int 1
  test "locals work"
    local let base: i32
      int 2
    local var value: i32
      call add_local
        var base
    set value
      binary +
        var value
        int 1
    binary =
      var value
      int 5
  test "bool let locals work"
    local let expected: bool
      bool true
    local let actual: bool
      call keep_flag
        var expected
    var actual
  test "bool let locals preserve false"
    if
      call keep_flag
        bool false
      bool false
      bool true
  test "bool var set flips true"
    if
      call flip_flag
        bool true
      bool false
      bool true
  test "bool var set flips false"
    call flip_flag
      bool false
  test "i64 var set works"
    binary =
      call add_wide_local
        i64 40
      i64 42
  test "f64 var set works"
    binary =
      call add_ratio_local
        float 41.5
      float 42
