You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/02/12 23:26:00 UTC
[jira] [Commented] (GROOVY-8707) += in CompileStatic dynamically
sets property instead of using setter
[ https://issues.apache.org/jira/browse/GROOVY-8707?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17035786#comment-17035786 ]
Eric Milles commented on GROOVY-8707:
-------------------------------------
Not sure why "a.num += 10" is written as {{ScriptBytecodeAdapter.setProperty(a.getNum() + 10, (Class)null, a, (String)"num")}} instead of using {{Groovy8707.setNum(int)}} like "a.num = 5" does. The two lines take different paths through AsmClassGenerator, so I need to do some back-tracking to see if there is an AST transform applied to "a.num = 5".
I also have an experiment that would turn all accesses to "num" in the example to field reads/writes. Accessing "num" from within the declaring class should be able to be a simple field access.
> += in CompileStatic dynamically sets property instead of using setter
> ---------------------------------------------------------------------
>
> Key: GROOVY-8707
> URL: https://issues.apache.org/jira/browse/GROOVY-8707
> Project: Groovy
> Issue Type: Bug
> Affects Versions: 2.5.1
> Reporter: death lord
> Priority: Minor
>
> Code:
> {code:groovy}
> import groovy.transform.CompileStatic
> @CompileStatic
> class A {
> int num
> static main(args) {
> def a = new A()
> a.num = 5
> a.num += 10
> }
> }
> {code}
> Main method compiles to:
> {code}
> A a = new A();
> byte var2 = 5;
> a.setNum(var2);
> Object var10001 = null;
> ScriptBytecodeAdapter.setProperty(a.getNum() + 10, (Class)null, a, (String)"num");
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)