Main.hx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. typedef BadType = {
  2. // should error but not yet
  3. var foo(private get, private set):Int;
  4. var foo2(never, never):Int;
  5. }
  6. typedef FooPrivateGetType = {
  7. var foo(private get, set):Int;
  8. }
  9. typedef FooType = {
  10. var foo(get, set):Int;
  11. }
  12. class Main {
  13. static function main() {
  14. final main = new Main();
  15. main.foo = 1;
  16. var privateObj:FooPrivateGetType = main;
  17. var obj:FooType = main; // err, should be allowed?
  18. privateObj = obj;
  19. obj = privateObj; // err
  20. }
  21. public var foo(private get, set):Int;
  22. function get_foo():Int {
  23. return 0;
  24. }
  25. function set_foo(v) {
  26. return v;
  27. }
  28. public var notAllowed(private get, private set):Int; // err
  29. function set_notAllowed(v):Int return 0;
  30. function get_notAllowed():Int return 0;
  31. public function new() {
  32. foo = 1;
  33. foo;
  34. @:bypassAccessor Rect.staticFoo = 1;
  35. @:privateAccess Rect.staticFoo = 1;
  36. Rect.staticFoo = 1; // err
  37. final rect = new Rect();
  38. rect.width = 1; // err
  39. rect.width;
  40. final shape:Shape = rect;
  41. shape.width = 1;
  42. shape.width; // err
  43. final bar = new Bar();
  44. bar.defaultPrivateSet = 1; // err
  45. @:bypassAccessor bar.defaultPrivateSet = 1;
  46. @:privateAccess bar.defaultPrivateSet = 1;
  47. @:privateAccess bar.width = 1;
  48. bar.width = 1; // err
  49. bar.width; // err
  50. bar.defaultNull = 1; // err
  51. bar.age;
  52. @:bypassAccessor bar.age = 1;
  53. @:privateAccess bar.age = 1;
  54. bar.age = 1; // err
  55. final child = new Child();
  56. @:privateAccess child.width = 1;
  57. }
  58. }
  59. interface Shape {
  60. var width(private get, set):Int;
  61. }
  62. interface PublicShape {
  63. var width(get, set):Int;
  64. }
  65. class PrivateRect implements PublicShape {
  66. public var width(get, private set):Int; // err
  67. function set_width(value:Int):Int {
  68. return value;
  69. }
  70. function get_width():Int {
  71. return 0;
  72. }
  73. }
  74. class Rect implements Shape {
  75. public static var staticFoo(default, private set):Int = 0;
  76. static function set_staticFoo(v) {
  77. return v;
  78. }
  79. public function new() {}
  80. public var width(get, private set):Int; // err
  81. function set_width(v):Int return 0;
  82. function get_width():Int return 0;
  83. }
  84. @:build(PropertyMacro.addIntProperty("age"))
  85. class Bar {
  86. public function new() {
  87. width = 2;
  88. }
  89. public var defaultNull(default, null):Int;
  90. public var defaultPrivateSet(default, private set):Int;
  91. function set_defaultPrivateSet(v):Int return v;
  92. var width(private get, private set):Int;
  93. function set_width(value:Int):Int {
  94. return value;
  95. }
  96. function get_width():Int {
  97. return 0;
  98. }
  99. }
  100. class Parent {
  101. var width(private get, private set):Int;
  102. function set_width(v):Int return 0;
  103. function get_width():Int return 0;
  104. }
  105. class Child extends Parent {
  106. public function new() {
  107. width = 0;
  108. super.width;
  109. super.width = 0;
  110. }
  111. }
  112. @:access(Element)
  113. class MainElement {
  114. public static function main() {
  115. new Element().foo;
  116. new Element().fooSet = false;
  117. }
  118. }
  119. class Element extends Entity {}
  120. class Entity {
  121. function new() {}
  122. var foo(private get, never):Bool;
  123. function get_foo():Bool
  124. return true;
  125. var fooSet(default, private set):Bool;
  126. function set_fooSet(v):Bool
  127. return fooSet = v;
  128. }