Skip to content

Commit

Permalink
Handle initialization block
Browse files Browse the repository at this point in the history
  • Loading branch information
Ao-senXiong committed May 2, 2024
1 parent f75590d commit c9157cf
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/pico/typecheck/PICONoInitVisitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pico.typecheck;

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

0 comments on commit c9157cf

Please sign in to comment.