[ 
https://issues.apache.org/jira/browse/GROOVY-12594?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18140520#comment-18140520
 ] 

ASF GitHub Bot commented on GROOVY-12594:
-----------------------------------------

codeconsole commented on PR #3121:
URL: https://github.com/apache/groovy/pull/3121#issuecomment-6717050125

   @daniellansun Merging current master into this PR made 
`VirtualAnnotationTest.virtualStaticAccessor_namedLikeClassProperty_writtenAsProperty`
 fail under `@CompileStatic`: `Over.sc()` returned `'OverbOverb'`.
   
   The cause is GROOVY-12613 (9d8259b8e3). Since that change, trait code keeps 
`name += 'b'` as a compound assignment instead of rewriting it to `name = name 
+ 'b'`. The type checker checks the read of `x op= y` on a copy of `x`, and 
this PR's `onMethodSelection` marks that copy dynamic. The code generator, 
though, reads through `x` itself, which was still bound to `Class.getName()`.
   
   3f0f494f76 carries the copy's dynamic resolution over to `x`, but only when 
no setter was selected for the write. It sits next to the GROOVY-12524 handling 
of extension getters. With master merged in (90fdac76bb), `traitx.*`, 
`groovy.transform.stc.*`, `org.codehaus.groovy.classgen.asm.sc.*`, 
`Groovy12524` and `Groovy12619` pass (5,247 tests).
   




> STC rejects a @Virtual trait static accessor read or written with property 
> syntax
> ---------------------------------------------------------------------------------
>
>                 Key: GROOVY-12594
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12594
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> import groovy.transform.Virtual
> @groovy.transform.CompileStatic
> trait T {
>     @Virtual static boolean isVr() { false }
>     static String sm() { vr ? 'yes' : 'no' }
> }
> class C implements T { static boolean isVr() { true } }
> class D implements T { }
> assert [C.sm(), D.sm()] == ['yes', 'no']
> {code}
> Actual: {{[Static type checking] - No such property: vr for Class or static 
> property for class: T}} with {{@CompileStatic}} or {{@TypeChecked}}. The same 
> error occurs in instance trait methods, for a @Virtual setter written as an 
> assignment or compound assignment, and for a @Virtual accessor of a super 
> trait. The method form {{isVr()}} compiles, and dynamic Groovy runs the 
> script.
> Expected: the script compiles, and the property reads and writes dispatch 
> through the implementing class like {{isVr()}} does, giving {{yes}} for {{C}} 
> and {{no}} for {{D}}.
> A @Virtual static is not promoted to the trait interface, so the type checker 
> finds no property on the trait for the receiver that the trait transformation 
> produces. The method form is resolved through the trait type checking 
> extension; the property form is not.
> Seen in 6.0.0 (the first version with @Virtual).
> PR: https://github.com/apache/groovy/pull/3121



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to