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


##########
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:
   I think we should test something like this
   ```Groovy
   class Person {
       String name
   }
   
   class People extends ArrayList<Person> {
       String name = 'the collection'
   }
   
   @groovy.transform.CompileStatic
   def test() {
       def people = new People()
       people.add(new Person(name: 'Alice'))
       people.add(new Person(name: 'Bob'))
   
       assert people.name == 'the collection'
       assert people*.name == ['Alice', 'Bob']
   }
   ```
   and the same with extension methods instead of fields.



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