daniellansun commented on code in PR #3058:
URL: https://github.com/apache/groovy/pull/3058#discussion_r4430099011


##########
src/main/java/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java:
##########
@@ -376,8 +378,12 @@ public void visitField(final FieldNode node) {
                 ClassNode declaringClass = node.getDeclaringClass();
                 if (declaringClass != null) {
                     if 
(StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(declaringClass, 
ClassHelper.LIST_TYPE)) {
-                        boolean spread = 
declaringClass.getDeclaredField(node.getName()) != node;
-                        pexp.setSpreadSafe(spread);
+                        boolean declaredField = 
declaringClass.getDeclaredField(node.getName()) == node;
+                        // GROOVY-12534: the virtual field for an extension 
setter is not an element
+                        // property. A declared field, or a real one-argument 
setter, is unchanged.
+                        if (declaredField || 
declaresUnarySetter(declaringClass, node.getName())) {
+                            pexp.setSpreadSafe(!declaredField);

Review Comment:
   When `declaredField` is true, the List (or subclass) actually owns that 
field, so the property targets the list receiver itself, not each element. 
`setSpreadSafe(false)` keeps that non-spread behavior. That matches the 
previous logic for a real declared field (`getDeclaredField(...) == node` 
already meant spread was false). GROOVY-12534 only changes the extension-method 
virtual-field path: those used to force `setSpreadSafe(true)`, which made 
`list.someExtProp` compile as element-wise access. Now we leave spread alone 
unless it is a declared field or a real unary setter.



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