Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8283

Field shadowing not considered in STC

    XMLWordPrintableJSON

Details

    Description

      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()
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              daniilo Daniil Ovchinnikov
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: