public enum Color {
  RED = 1 << 0,
  GREEN = 1 << 1,
  BLUE = 1 << 2;
  public static Color[] all() { return { RED, GREEN, BLUE }; }
}

public string takes_enum(Color color) {
  var retval = "";
  foreach (var c in Color.all()) {
    if((color&c) != 0) {
      if(retval != "") retval += " | ";
      retval += @"$c";
    }
  }
  return retval;
}

public Color takes_int(int bla) {
  return Color.GREEN;
}

int main(string[] args) {

  // Normal calls should work
  print("Red: %s\n", takes_enum(Color.RED));

  // Unscoped enum const is new
  print("Red: %s\n", takes_enum(RED));
  Color col = GREEN;
  print("Green: %s\n", col.to_string());

  {
    // environment should override unscoped enum
    var RED=Color.GREEN;
    print("Green: %s\n", takes_enum(RED));
  }

  // should not descend any deeper than one level: compiler error
  //takes_enum(takes_int(RED));

  // should work with flags
  print("Red and green: %s\n", takes_enum(RED|GREEN));

  // should also work for return values
  print("Green: %s\n", works_for_retval().to_string());

  return 0;
}


public Color works_for_retval() {
  return GREEN;
}
