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

STC claims non-existent Diamond in Anonymous Inner Class with Generics

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.4.0-beta-3
    • Fix Version/s: 2.4.4
    • Component/s: Static Type Checker
    • Labels:
      None
    • Environment:
      Groovy Version: 2.4.0-beta-3 JVM: 1.8.0_25 Vendor: Oracle Corporation OS: Mac OS X

      Description

      In following code, STC error with variable x.

      [Static type checking] - Cannot use diamond <> with anonymous inner classes

      But diamond is not used for x.

      interface Cls<T> {
          void foo(T t)
      }
      
      @groovy.transform.TypeChecked
      def func() {
          Cls<String> x = new Cls<String>(){ // [Static type checking] - Cannot use diamond <> with anonymous inner classes
                                             // why?
              void foo(String t){}
          }
          Cls y = new Cls<String>(){ // OK
              void foo(String t){}
          }
          Cls<String> z = new Cls<>(){ // [Static type checking] - Cannot use diamond <> with anonymous inner classes
                                       // fair enough
              public void foo(String t){}
          }
      }
      
      

        Attachments

        1. Test.groovy
          0.5 kB
          UEHARA Junji

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              uehaj UEHARA Junji
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: