< prev index next >

test/langtools/tools/javac/SuperInit/EarlyAssignments.java

Print this page
*** 1,10 ***
--- 1,11 ---
  /*
   * @test /nodynamiccopyright/
   * @bug 8325805
   * @summary Permit non-superclass instance field assignments before this/super in constructors
   * @compile/fail/ref=EarlyAssignments.out -XDrawDiagnostics EarlyAssignments.java
+  * @enablePreview
   */
  public class EarlyAssignments {
  
      public static class Inner1 {
          public int x;

*** 15,13 ***
              Inner1.this.x = 123;            // OK - "x" belongs to this class
              super();
          }
  
          public Inner1(int y) {
!             y = x;                          // FAIL - early 'this' reference
!             y = this.x;                     // FAIL - early 'this' reference
!             y = Inner1.this.x;              // FAIL - early 'this' reference
              super();
          }
  
          public class Inner1a extends Inner1 {
              public int z;
--- 16,13 ---
              Inner1.this.x = 123;            // OK - "x" belongs to this class
              super();
          }
  
          public Inner1(int y) {
!             y = x;                          // OK - "x" belongs to this class
!             y = this.x;                     // OK - "x" belongs to this class
!             y = Inner1.this.x;              // OK - "x" belongs to this class
              super();
          }
  
          public class Inner1a extends Inner1 {
              public int z;

*** 92,23 ***
      public static class Inner4 {
          public int x;
  
          public Inner4() {
              x = 0;                              // OK
!             x = x + 1;                          // FAIL - illegal early access
              super();
          }
  
          public Inner4(int a) {
              this.x = 0;                         // OK
!             this.x = this.x + 1;                // FAIL - illegal early access
              super();
          }
  
          public Inner4(char a) {
              Inner4.this.x = 0;                  // OK
!             Inner4.this.x = Inner4.this.x + 1;  // FAIL - illegal early access
              super();
          }
      }
  
      public static class Inner5 extends Inner4 {
--- 93,23 ---
      public static class Inner4 {
          public int x;
  
          public Inner4() {
              x = 0;                              // OK
!             x = x + 1;                          // OK
              super();
          }
  
          public Inner4(int a) {
              this.x = 0;                         // OK
!             this.x = this.x + 1;                // OK
              super();
          }
  
          public Inner4(char a) {
              Inner4.this.x = 0;                  // OK
!             Inner4.this.x = Inner4.this.x + 1;  // OK
              super();
          }
      }
  
      public static class Inner5 extends Inner4 {

*** 166,6 ***
--- 167,15 ---
          public Inner8() {
              this.new Inner8a().x = 1;           // FAIL - illegal early access
              super();
          }
      }
+ 
+     public static class Inner9 {
+         int x = 1;
+         int y;
+         Inner9() {
+             y = x; // FAIL, x has an initializer
+             super();
+         }
+     }
  }
< prev index next >