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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

JIRA jira@apache.org
Daniil Ovchinnikov created GROOVY-8283:
------------------------------------------

             Summary: 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


{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
(v6.4.14#64029)
Loading...