Copilot commented on code in PR #2672:
URL: https://github.com/apache/groovy/pull/2672#discussion_r3533058955


##########
subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/generation/BaseGenerator.java:
##########
@@ -187,6 +187,14 @@ protected BlockStatement 
wrapAssertionBooleanExpression(ClassNode type, MethodNo
      */
     protected BooleanExpression 
addCallsToSuperMethodNodeAnnotationClosure(final ClassNode type, final 
MethodNode methodNode, final Class<? extends Annotation> annotationType, 
BooleanExpression booleanExpression, boolean isPostcondition) {
         List<AnnotationNode> contractElementAnnotations = 
AnnotationUtils.getAnnotationNodeInHierarchyWithMetaAnnotation(type.getSuperClass(),
 methodNode, ClassHelper.makeWithoutCaching(annotationType));
+        if (!isPostcondition) {
+            // An unwoven precondition (@Requires(woven = false)) never 
contributes to generated
+            // assertions — inherited arms included, so an override does not 
weave a check its
+            // declaring class deliberately left to existing enforcement.
+            contractElementAnnotations = contractElementAnnotations.stream()
+                    .filter(a -> !isUnwoven(a))
+                    .collect(java.util.stream.Collectors.toList());
+        }
         if (contractElementAnnotations.isEmpty()) {
             methodNode.putNodeMetaData(META_DATA_USE_INLINE_MODE, 
Boolean.TRUE);
         } else {

Review Comment:
   `META_DATA_USE_INLINE_MODE` is only ever set to `true` and never cleared 
when inherited contract annotations are present. Since preconditions are 
injected before postconditions (DomainModelInjectionVisitor), enabling inline 
mode while processing preconditions can incorrectly cause postcondition weaving 
to take the inline path even when inherited postconditions exist, which would 
skip inherited postcondition checks. With the new unwoven-precondition 
filtering, more methods will hit the “empty inherited preconditions” path and 
set this flag, increasing the risk of this cross-contamination.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to