Skip to content

Commit c9157cf

Browse files
committed
Handle initialization block
1 parent f75590d commit c9157cf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/main/java/pico/typecheck/PICONoInitVisitor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package pico.typecheck;
22

3+
import static org.checkerframework.javacutil.TreePathUtil.isTopLevelAssignmentInInitializerBlock;
34
import static pico.typecheck.PICOAnnotationMirrorHolder.BOTTOM;
45
import static pico.typecheck.PICOAnnotationMirrorHolder.IMMUTABLE;
56
import static pico.typecheck.PICOAnnotationMirrorHolder.MUTABLE;
@@ -378,6 +379,10 @@ private void checkMutation(Tree node, ExpressionTree variable) {
378379
// If the enclosing method is constructor, we don't need to check the receiver type
379380
return;
380381
}
382+
if (isTopLevelAssignmentInInitializerBlock(getCurrentPath())) {
383+
// If the assignment is in initializer block, we don't need to check the receiver type
384+
return;
385+
}
381386
// Cannot use receiverTree = TreeUtils.getReceiverTree(variable) to determine if it's
382387
// field assignment or not. Because for field assignment with implicit "this", receiverTree
383388
// is null but receiverType is non-null. We still need to check this case.

0 commit comments

Comments
 (0)