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

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

eric-milles commented on PR #1767:
URL: https://github.com/apache/groovy/pull/1767#issuecomment-2528805577

   For circumstances that go through `ScriptBytecodeAdapter`, the sender class 
is not propagated to `MetaClassImpl`.  Access checks give different results, 
since the sender is re-mapped to the object.
   
   * 
https://github.com/apache/groovy/blob/981928053477e7d7790e0b6000e7a4dd5b45b583/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java#L472
   * 
https://github.com/apache/groovy/blob/981928053477e7d7790e0b6000e7a4dd5b45b583/src/main/java/org/codehaus/groovy/runtime/ScriptBytecodeAdapter.java#L504
   
   ```groovy
               package p
               class A {}
               class B {}
               class C {
                   boolean setter
                   protected A foo = new A()
                   A getFooA() { return this.@foo }
                   void setFoo(A a) { setter = true; this.@foo = a }
               }
               class D extends C {
                   protected B foo = new B() // hides A#foo; should hide 
A#setFoo in subclasses
                   B getFooB() { return this.@foo }
               }
   ```
   
   ```groovy
   import p.*
               class E extends D {}
               def e = new E()
               e.foo = null // not the field from this perspective
               assert e.setter // fails
   ```




> 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
>
> {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
(v8.20.10#820010)

Reply via email to