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

Base class property causes CCE

    XMLWordPrintableJSON

Details

    Description

      playground.groovy
      abstract class BaseClass {
          def prop = 42
      }
      
      abstract class BaseClass2 {
          def prop = 69
      }
      
      @groovy.transform.CompileStatic
      class Impl extends BaseClass {
          def usage() {
              new BaseClass2() {
                  def foo() {
                      prop
                  }
              }
          }
      }
      
      assert new Impl().usage().foo() == 69
      

      Output:

      Caught: java.lang.ClassCastException: Impl$1 cannot be cast to BaseClass
      java.lang.ClassCastException: Impl$1 cannot be cast to BaseClass
      	at Impl$1.foo(playground.groovy)
      	at Impl$1$foo.call(Unknown Source)
      	at playground.run(playground.groovy:20)
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 0.5h
                0.5h