Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,20 @@ public void visitIdent(JCIdent tree) {
analyzeSymbol(tree);
}

boolean isIndexed = false;

@Override
public void visitIndexed(JCArrayAccess tree) {
boolean previewIsIndexed = isIndexed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean previousIsIndexed?

try {
isIndexed = true;
scan(tree.indexed);
} finally {
isIndexed = previewIsIndexed;
}
scan(tree.index);
}

@Override
public void visitSelect(JCFieldAccess tree) {
SelectScanner ss = new SelectScanner();
Expand Down Expand Up @@ -1434,7 +1448,9 @@ void analyzeSymbol(JCTree tree) {
}
// Field may not have an initializer
if ((sym.flags() & HASINIT) != 0) {
reportPrologueError(tree, sym, true);
if (!sym.type.hasTag(ARRAY) || !isIndexed) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work for complex ones like (this.a = stuff)[b] = 5?

Maybe we can try updating isInLHS to point to a JCTree and all the tests to be something like tree == isInLHS so this just won't run for array indexed trees?

reportPrologueError(tree, sym, true);
}
return;
}
// cant reference an instance field before a this constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @bug 8324873
* @summary Test valid placements of super()/this() in constructors
* @enablePreview
* @ignore fails at execution time because of Optional
*/

public value class ValueClassSuperInitGood {
Expand Down Expand Up @@ -450,6 +449,15 @@ class Nested {{ System.out.println(x); }} // class is NOT instantiated - O
}
}

public static value class Test22 {
private final int[] data = new int[10];
Test22() {
for (int i = 0; i < data.length; i++) {
data[i] = i; // OK we are assigning to an array component
}
}
}

public static void main(String[] args) {
new Test0();
new Test1() {};
Expand Down Expand Up @@ -493,5 +501,6 @@ public static void main(String[] args) {
new Test19(123);
new Test20();
new Test21();
new Test22();
}
}