From c9157cfe9602dbdedba5eea96d3acb2dafc0b5e5 Mon Sep 17 00:00:00 2001 From: Aosen Xiong Date: Wed, 1 May 2024 20:22:17 -0400 Subject: [PATCH] Handle initialization block --- src/main/java/pico/typecheck/PICONoInitVisitor.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/pico/typecheck/PICONoInitVisitor.java b/src/main/java/pico/typecheck/PICONoInitVisitor.java index cc620ab..8c7893b 100644 --- a/src/main/java/pico/typecheck/PICONoInitVisitor.java +++ b/src/main/java/pico/typecheck/PICONoInitVisitor.java @@ -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; @@ -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.