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

enum added to List fails TypeChecked

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0, 3.0.1
    • Fix Version/s: 2.5.10, 3.0.2
    • Component/s: None
    • Labels:
      None
    • Environment:
      CentOS

      Description

       

      import groovy.transform.TypeChecked
      
      @TypeChecked
      class MyClass {
      
          interface Foo {}
      
          enum Bar implements Foo {
              AA
          }    
          
          void F() {
              List<Foo> g = []
              g.add(Bar.AA)
          }
      }
      
      new MyClass()
      

      Put this in a file "script.groovy" and call "groovy script.groovy"

      Expected: No output
      Actual: 

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      <path to file>/Script.groovy: 14: [Static type checking] - Cannot call java.util.List <Foo>#add(MyClass$Foo) with arguments [MyClass$Bar] 
       @ line 14, column 9.
                 g.add(Bar.AA)
                 ^
      1 error

      Does not occur in 3.0.0-rc-3 or earlier.

      Looks similar to GROOVY-8960 but does not occur in 2.5.5

      Workaround: Add cast "g.add(Bar.AA as Foo)"

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              tofor Ian
            • Votes:
              0 Vote for this issue
              Watchers:
              3 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 - 1.5h
                1.5h