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

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

jonenst commented on PR #1767:
URL: https://github.com/apache/groovy/pull/1767#issuecomment-6682646613

   In my understanding, it's just that getProperty/setProperty used to do
   
   ```
   InvokerHelper.setProperty(receiver, messageName, messageArgument);
   ```
   
   where invokerHelper.setProperty does a null check and replace with 
NullObject here: 
https://github.com/apache/groovy/blob/d1710f88eb6ac98a941626db47963a063f1c50e0/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java#L184
   
   NullObject then throws the nice message here: 
https://github.com/apache/groovy/blob/d1710f88eb6ac98a941626db47963a063f1c50e0/src/main/java/org/codehaus/groovy/runtime/NullObject.java#L109
   
   but 
https://github.com/apache/groovy/commit/f5914b9e76a085248c0ef1ca79c8e1e79ab9df7a#diff-3d4ec8c308fcf2a37f1387656356af5b02ae271cce33d01671fe461fc920cc4fL471
   
   changed it to
   ```groovy
   if (receiver instanceof GroovyObject) {
     var groovyObject = (GroovyObject) receiver;
     groovyObject.setProperty(messageName, messageArgument);
   } else {
     MetaClass metaClass = InvokerHelper.getMetaClass(receiver);
     metaClass.setProperty(senderClass, receiver, messageName, messageArgument, 
false, false);
   }
   ```
   for null the instanceof checks return false so it goes ot 
InvokerHelper.getMetaClass(receiver), there it falls through some more 
instanceof checks 
https://github.com/apache/groovy/blob/d1710f88eb6ac98a941626db47963a063f1c50e0/src/main/java/org/codehaus/groovy/runtime/InvokerHelper.java#L581
 and ends up doing the NPE I think here, there is never a null check to replace 
with nullobject in this sequence : 
https://github.com/apache/groovy/blob/d1710f88eb6ac98a941626db47963a063f1c50e0/src/main/java/org/codehaus/groovy/runtime/metaclass/MetaClassRegistryImpl.java#L377




> Field shadowing not considered in STC
> -------------------------------------
>
>                 Key: GROOVY-8283
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8283
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>    Affects Versions: 2.4.12
>            Reporter: Daniil Ovchinnikov
>            Assignee: Eric Milles
>            Priority: Major
>              Labels: breaking
>             Fix For: 5.0.0-rc-1
>
>
> {code}
> import groovy.transform.CompileStatic
> @CompileStatic class A {}
> @CompileStatic class B {}
> @CompileStatic class Parent {
>   protected A ff = new A()
>   A getFf() { ff }
> }
> @CompileStatic class Child extends Parent {
>   protected B ff = new B()
> }
> @CompileStatic class Usage extends Child {
>   def test() {
>     println ff        // A@id
>     println getFf()   // A@id
>     println this.@ff  // B@id
>   }
>   def test2() {
>     I.wantsB(ff)        // 
> ScriptBytecodeAdapter.castToType(((Usage)this).getFf(), B.class)) is 
> generated (wrong)
>     I.wantsB(getFf())   // [STC] - Cannot find matching method I#wantsB(A)
>     I.wantsB(this.@ff)  // [STC] - Cannot find matching method I#wantsB(A) 
> (wrong)
>   }
> }
> @CompileStatic class I {
>   static void wantsB(B b) {}
> }
> new Usage().test()
> {code}



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

Reply via email to