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


##########
subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/LoopVariantASTTransformation.java:
##########
@@ -129,6 +129,11 @@ public void visit(final ASTNode[] nodes, final SourceUnit 
source) {
 
         // Inject: save at start, check at end
         injectAtLoopBodyStartAndEnd(loopStatement, savePrev, block(saveCurr, 
decreaseCheck));
+
+        // The variant closure lived inside an annotation, so its variable 
references were never
+        // resolved; re-run scope analysis now that they are real loop-body 
statements so that
+        // @TypeChecked/@CompileStatic can see their declared types.
+        LoopContractSupport.resolveVariableScopes(source);

Review Comment:
   `LoopContractSupport` is not defined anywhere in the repo, so this will fail 
compilation. To re-run scope analysis after moving the variant expression out 
of the annotation closure, invoke `VariableScopeVisitor` on the SourceUnit’s 
classes (similar to other AST transforms in core Groovy).



##########
subprojects/groovy-contracts/src/main/java/org/apache/groovy/contracts/ast/LoopInvariantASTTransformation.java:
##########
@@ -98,6 +98,11 @@ public void visit(final ASTNode[] nodes, final SourceUnit 
source) {
         wrapped.setSourcePosition(annotation);
 
         injectAtLoopBodyStart(loopStatement, wrapped);
+
+        // The invariant closure lived inside an annotation, so its variable 
references were never
+        // resolved; re-run scope analysis now that they are real loop-body 
statements so that
+        // @TypeChecked/@CompileStatic can see their declared types.
+        LoopContractSupport.resolveVariableScopes(source);

Review Comment:
   `LoopContractSupport` does not exist in this module/package, so this call 
will not compile. If the goal is to re-run variable scope analysis after 
injecting statements (so `@TypeChecked/@CompileStatic` can see local variable 
references), call `VariableScopeVisitor` directly (as done in several core 
Groovy AST transforms).



-- 
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