groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Is FieldsAndPropertiesStaticCompileTest#testUseGetterFieldAccess really correct?
Date Fri, 24 Nov 2017 00:46:01 GMT
Hi all,

the test is defined as this:

>     void testUseGetterFieldAccess() {
>         assertScript '''
>                     class A {
>                             boolean getterCalled = false
> 
>                             protected int x
>                             public int getX() {
>                                 getterCalled = true
>                                 x
>                             }
>                     }
>                     class B extends A {
>                         void usingGetter() {
>                             this.x
>                         }
>                     }
>                     B b = new B()
>                     b.usingGetter()
>                     assert b.isGetterCalled() == true
>                 '''
>         assert astTrees['B'][1].contains('INVOKEVIRTUAL B.getX')
>     }

The test was written as a reaction to GROOVY-5619, which is to ensure 
that we do not call a setter in this case... only there is no setter 
here. Instead this test fixates the behaviour of the static compiler to 
call a getter instead of directly accessing the field. Direct access to 
the field is what is required for GROOVY-8385

In my opinion the test is wrong, but I'd like to hear others about this.

And another point. We seem to have no similar test for dynamic Groovy. 
Groovy does use direct field access if the field is available on "this". 
But the question here is if that extends to all super classes. In my 
opinion it should.

If I get no vetos I will push a fix for this for all current groovy versions

bye Jochen

Mime
View raw message