Main.hx 889 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. abstract MyInt(Int) from Int to Int {
  2. @:op(A += B)
  3. public inline function addEq(x:Int):MyInt {
  4. return this += x;
  5. }
  6. @:op(A++)
  7. public inline function increment():MyInt {
  8. return this++;
  9. }
  10. }
  11. class MyClass {
  12. final field:MyInt = 1;
  13. function func():Void {
  14. final local:MyInt = 1;
  15. // --- overriden operators ---
  16. field++; // Error: The field or identifier field is not accessible for writing
  17. local++;
  18. field += 1;
  19. local += 1; // Error: Cannot assign to final
  20. // --- raw operators ---
  21. field--; // Error: The field or identifier field is not accessible for writing
  22. local--; // Error: Cannot assign to final
  23. field -= 1; // Error: Cannot access field or identifier field for writing
  24. local -= 1; // Error: Cannot assign to final
  25. // --- method calls ---
  26. field.addEq(1);
  27. local.addEq(1);
  28. field.increment();
  29. local.increment();
  30. }
  31. }
  32. function main() {
  33. }