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

Map.Entry<K,V>#key and #value fail to infer type correctly under @StaticCompile

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.0
    • 2.0.1
    • Static compilation
    • None
    • Ubuntu 12.04, Oracle JVM 1.7.0_05

    Description

      import groovy.transform.CompileStatic
      @CompileStatic
      class BrokenCompileStaticTest extends GroovyTestCase {
        void testMapForEachAttribute() {
          def result = ""
          def sum = 0
          for ( Map.Entry<String, Integer> it in [a:1, b:3].entrySet() ) {
             result += it.key
             sum += it.value
          }
          assert result == "ab"
          assert sum == 4
        }
      }
      

      fails to infer the type of Map.Entry#key and #value, regardless of the proper generic type in the for-in loop definition.

      Message:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      /home/steven/BrokenCompileStaticTest.groovy: 9: [Static type checking] - Cannot find matching method int#plus(java.lang.Object <V>)
       @ line 9, column 8.
                sum += it.value
                ^
      
      1 error
      

      Also, shouldn't groovy report both static type errors, instead of just the first?

      Attachments

        1. BrokenCompileStaticTest.groovy
          0.3 kB
          Steven Ruppert

        Issue Links

          Activity

            People

              melix Cédric Champeau
              blendmaster Steven Ruppert
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: