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

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

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

   hi @eric-milles , I think changes around GROOVY-8283 (specifically changes 
to ScriptBytecodeAdapter.java setProperty in commit 
f5914b9e76a085248c0ef1ca79c8e1e79ab9df7a ) trigger an arguable regression in 
error messages, visible in groovysh. Is this a regression and maybe worth 
fixing ?
   
   groovy 4 nice errors:
   ```
   $ groovy-4.0.33/bin/groovysh
   Groovy Shell (4.0.33, JVM: 17.0.8)
   groovy:000> foo = null
   ===> null
   groovy:000> foo.bar
   ERROR java.lang.NullPointerException:
   Cannot get property 'bar' on null object
   groovy:000> foo.bar=3
   ERROR java.lang.NullPointerException:
   Cannot set property 'bar' on null object
   groovy:000> baz = 'bar'
   ===> bar
   groovy:000> foo."$baz"
   ERROR java.lang.NullPointerException:
   Cannot get property 'bar' on null object
   groovy:000> foo."$baz" = 3
   ERROR java.lang.NullPointerException:
   Cannot set property 'bar' on null object
   ```
   
   groovy 5 less nice errors (except for static property getter using 
invokedynamic)
   ```
   $ groovy-5.0.2/bin/groovysh
   Groovy Shell (5.0.2, JVM: 17.0.8, Term: linux)
   groovy> foo = null
   groovy> foo.bar
   NullPointerException: Cannot get property 'bar' on null object
   groovy> foo.bar=3
   NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
   groovy> baz = 'bar'
   groovy> foo."$baz"
   NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
   groovy> foo."$baz" = 3
   NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
   ```
   
   groovy6 static property setter fixed (setter now uses invokedynamic 
https://github.com/apache/groovy/pull/2674 )  but not computed property name:
   ```
   $ groovy-6.0.0/bin/groovysh
   Groovy Shell (6.0.0, JVM: 17.0.8, Term: linux)
   groovy> foo = null
   groovy> foo.bar
   NullPointerException: Cannot get property 'bar' on null object
   groovy> foo.bar=3
   NullPointerException: Cannot set property 'bar' on null object
   groovy> baz = 'bar'
   groovy> foo."$baz"
   NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
   groovy> foo."$baz" = 3
   NullPointerException: Cannot invoke "Object.getClass()" because "obj" is null
   groovy> 
   ```
   
   (note: commenting here since I couldn't find a PR for 
f5914b9e76a085248c0ef1ca79c8e1e79ab9df7a but it has the same message "propagate 
sender class for `getProperty` and `setProperty`" as other commits like 
7c86803ca48aad and 4dbda66ab4cffeee which have   "GROOVY-8283"  in their 
message)




> 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