You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TargetClass.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. @testcase definitions for introduced type test cases
  3. --- initial variants
  4. // -------- error "can't emit cast for NotFoundType() to PrimitiveType(int)
  5. //double i = (double) i2() - i1();
  6. //int i = (int) this.someInt();
  7. // -------- compiler RuntimeException: "Unsupported emit on NotFoundType" Type.java:460
  8. //double j = (double) (d2() - d1());
  9. //if ((d2() - d1()) instanceof float) { doTrue(); }
  10. //if ((d2() - d1()) instanceof int) { doTrue(); }
  11. //if ((d2() - d1()) instanceof short) { doTrue(); }
  12. //if ((d2() - d1()) instanceof double) { doTrue(); }
  13. //if ((i2() - i1()) instanceof int) { doTrue(); }
  14. //if (!((getBoolean()) instanceof boolean)) { Tester.check(false,"boolean"); }
  15. //if (!((getChar()) instanceof char)) { Tester.check(false,"char"); }
  16. //if (!((getByte()) instanceof byte)) { Tester.check(false,"byte"); }
  17. if (d2 instanceof double) { doTrue(); }
  18. // ------ expecting error, get compiler RuntimeException
  19. if (!((doVoid()) instanceof Void)) { Tester.check(false,"void"); }
  20. // -------- NPE NewInstanceExpr.java:287
  21. //InnerClass i = this.new InnerClass();
  22. //InnerClass i = getThis().new InnerClass();
  23. --- generalization of initial variants
  24. primitive type not found:
  25. either the introduced-on type or the method type of it
  26. --- possibly-relevant variants
  27. [failingTypeExpressions: instanceof, cast, qualified-new]
  28. x [introduced|normal|subclass]
  29. x [static|{default}]
  30. x [methods|field initializers]
  31. x [types=[String|Object|Type]|primitiveTypes=[boolean|...]]
  32. --- actual variants
  33. [failingTypeExpressions]
  34. x [introduced|subclass]
  35. x [methods|field initializers]
  36. x [primitiveTypes]
  37. except cast expression only for introduced methods - uncertain here
  38. */
  39. class Type {}
  40. public class TargetClass {
  41. TargetClass getThis() { return this ; }
  42. boolean getboolean() { return (this != null); }
  43. byte getbyte() { return '\1'; }
  44. char getchar() { return '\1'; }
  45. short getshort() { return 0; }
  46. int getint() { return 0; }
  47. long getlong() { return 1l; }
  48. float getfloat() { return 1f; }
  49. double getdouble() { return 1d; }
  50. String getstring() { return ""; }
  51. void doVoid() { }
  52. Type getType() { return null; }
  53. /** run PUREJAVA variant of the tests */
  54. public static void main(String[] args) {
  55. PureJava me = new PureJava();
  56. me.run();
  57. if (!me.result_cast) Util.fail("me.result_cast");
  58. if (!me.result_inner) Util.fail("me.result_inner");
  59. }
  60. public class InnerClass {
  61. public boolean valid() {
  62. return (null != this);
  63. }
  64. }
  65. }
  66. /** PUREJAVA variant of the tests */
  67. class PureJava extends TargetClass {
  68. public void run() {
  69. instanceOf();
  70. cast();
  71. newInner();
  72. }
  73. public void newInner() {
  74. InnerClass i = this.new InnerClass();
  75. if (!i.valid()) Util.fail("this.new InnerClass()");
  76. InnerClass j = getThis().new InnerClass();
  77. if (!j.valid()) Util.fail("getThis().new InnerClass()");
  78. Util.signal("inner");
  79. }
  80. public void cast() {
  81. boolean boolean_1 = getboolean();
  82. boolean boolean_2 = (boolean) getboolean();
  83. boolean boolean_3 = (boolean) this.getboolean();
  84. byte byte_1 = getbyte();
  85. byte byte_2 = (byte) getbyte();
  86. byte byte_3 = (byte) this.getbyte();
  87. char char_1 = getchar();
  88. char char_2 = (char) getchar();
  89. char char_3 = (char) this.getchar();
  90. short short_1 = getshort();
  91. short short_2 = (short) getshort();
  92. short short_3 = (short) this.getshort();
  93. int int_1 = getint();
  94. int int_2 = (int) getint();
  95. int int_3 = (int) this.getint();
  96. long long_1 = getlong();
  97. long long_2 = (long) getlong();
  98. long long_3 = (long) this.getlong();
  99. float float_1 = getfloat();
  100. float float_2 = (float) getfloat();
  101. float float_3 = (float) this.getfloat();
  102. double double_1 = getdouble();
  103. double double_2 = (double) getdouble();
  104. double double_3 = (double) this.getdouble();
  105. //X X_1 = getX();
  106. //X X_2 = (X) getX();
  107. //X X_3 = (X) this.getX();
  108. Util.signal("cast");
  109. }
  110. public void instanceOf() {
  111. // -------- RuntimeException: "Unsupported emit on NotFoundType" Type.java:460
  112. /*
  113. if (!((getBoolean()) instanceof Boolean)) { Util.fail("boolean"); }
  114. if (!((getChar()) instanceof char)) { Util.fail("char"); }
  115. if (!((getByte()) instanceof byte)) { Util.fail("byte"); }
  116. if (!((getShort()) instanceof short)) { Util.fail("short"); }
  117. if (!((getInt()) instanceof int)) { Util.fail("int"); }
  118. if (!((getLong()) instanceof long)) { Util.fail("long"); }
  119. if (!((getFloat()) instanceof float)) { Util.fail("float"); }
  120. if (!((getDouble()) instanceof double)) { Util.fail("double"); }
  121. */
  122. // ------ todo: expecting error, get RuntimeException
  123. //if (!((doVoid()) instanceof Void)) { Tester.check(false,"void"); }
  124. Util.signal("instanceOf");
  125. }
  126. // ---------- field initializer
  127. interface Result { public boolean run();}
  128. boolean result_inner =
  129. new Result() {
  130. public boolean run() {
  131. TargetClass.InnerClass i = ((TargetClass) PureJava.this).new InnerClass();
  132. if (!i.valid()) Util.fail("this.new InnerClass()");
  133. TargetClass.InnerClass j = ((TargetClass) getThis()).new InnerClass();
  134. if (!j.valid()) Util.fail("getThis().new InnerClass()");
  135. Util.signal("innerfield");
  136. return i.valid() && j.valid();
  137. }
  138. }.run();
  139. boolean result_cast =
  140. new Result() {
  141. public boolean run() {
  142. boolean boolean_1 = getboolean();
  143. boolean boolean_2 = (boolean) getboolean();
  144. boolean boolean_3 = (boolean) PureJava.this.getboolean();
  145. byte byte_1 = getbyte();
  146. byte byte_2 = (byte) getbyte();
  147. byte byte_3 = (byte) PureJava.this.getbyte();
  148. char char_1 = getchar();
  149. char char_2 = (char) getchar();
  150. char char_3 = (char) PureJava.this.getchar();
  151. short short_1 = getshort();
  152. short short_2 = (short) getshort();
  153. short short_3 = (short) PureJava.this.getshort();
  154. int int_1 = getint();
  155. int int_2 = (int) getint();
  156. int int_3 = (int) PureJava.this.getint();
  157. long long_1 = getlong();
  158. long long_2 = (long) getlong();
  159. long long_3 = (long) PureJava.this.getlong();
  160. float float_1 = getfloat();
  161. float float_2 = (float) getfloat();
  162. float float_3 = (float) PureJava.this.getfloat();
  163. double double_1 = getdouble();
  164. double double_2 = (double) getdouble();
  165. double double_3 = (double) PureJava.this.getdouble();
  166. //X X_1 = getX();
  167. //X X_2 = (X) getX();
  168. //X X_3 = (X) this.getX();
  169. Util.signal("castfield");
  170. return (boolean_1 && boolean_2 && boolean_3);
  171. }
  172. }.run();
  173. }