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

Failed to parse/compile generic methods with "extends"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.4.16, 3.0.0-alpha-4, 2.5.6
    • 3.0.0-rc-1, 2.5.18
    • Static compilation
    • None

    Description

       

      import groovy.transform.CompileStatic
      
      // This bug affects: groovy-2.4.16, groovy-2.5.6, groovy-3.0.0-alpha-4
      // This bug also affect IDEA's syntax parser
      
      interface X<T> {
          // Intellij IDEA reports that 'public' is not necessary
          // BUT without the 'public' modifier, there is a syntax error
          public <T> T foo(T o);
      }
      interface Y<T> {
          public <O extends T> O foo(O o);
      }
      
      @CompileStatic
      class TestGroovyGeneric {
          static void main(String[] args) {
              def x = new X<String>() {
                  // it compiles
                  // BUT: Intellij IDEA reports: ERROR: Method 'foo' is not implemented
                  @Override
                  String foo(String o) { return o }
              }
      
              // Strangely, such code compiles
              // BUT: Intellij IDEA reports: ERROR: Method 'foo' is not implemented
              def y1 = new Y<String>() {
                  @Override
                  public <String> String foo(String o) { return o }
              }
      
              // Can not compile:
              // BUT: Intellij IDEA reports no error ....
              def y2 = new Y<String>() {
                  @Override
                  String foo(String o) { return o }
              }
          }
      }
      
      

       

      Attachments

        1. image-2019-03-30-13-10-20-819.png
          226 kB
          Xiaoguang Wang

        Issue Links

          Activity

            People

              emilles Eric Milles
              wxiaoguang Xiaoguang Wang
              Votes:
              0 Vote for this issue
              Watchers:
              4 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 - 1h
                  1h