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 2022/02/05 15:32:00 UTC

[jira] [Commented] (GROOVY-8283) Field shadowing not considered in STC

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

Eric Milles commented on GROOVY-8283:
-------------------------------------

Dynamic and static compilation both select the public accessor of A.  It is not a simple matter of "protected B ff" shadows "protected A ff".  There is some confusion in STC because it searches class by class up the type hierarchy and stops at the field of B.

[~paulk] [~blackdrag]  Do you think there is anything left to do here?  I suppose STC inference could match the runtime, but there are other instances of this happening since property resolution is actually split into two parts ({{StaticTypeCheckingVisitor}} and {{StaticTypesCallSiteWriter}}).  GROOVY-6277 is one example.  Here is another: https://github.com/groovy/groovy-eclipse/issues/1326

> 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
>            Priority: Major
>
> {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.1#820001)