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

STC: return type checking for generic, covariant property gives false error

    XMLWordPrintableJSON

Details

    Description

      Follow up to GROOVY-7691. When getter generated for property is used, return type check fails.

                  import groovy.transform.*
      
                  @CompileStatic
                  @TupleConstructor(includeFields=true)
                  abstract class A<N extends Number> {
                      final N number
                  }
      
                  @CompileStatic
                  class C<L extends Long> extends A<L> {
                      C(L longNumber) {
                          super(longNumber)
                      }
      
                      L getValue() {
                          return getNumber() // property method stubbed by StaticTypeCheckingVisitor
                      }
                  }
      
                  assert new C<Long>(42L).value == 42L
      

      "[Static type checking] - Cannot return value of type N on method returning type L"

      StaticTypeCheckingVisitor has set the wrong declaring class for getNumber and so generics resolution from N to Long fails.

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            0 Vote for this issue
            Watchers:
            2 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 - 20m
                20m