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

Type inference breaks in longer transitive generic structures

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.6, 2.3.0, 2.4.0-beta-3, 4.0.13
    • 5.0.0-alpha-11
    • Static Type Checker
    • None

    Description

      class Test {
          @CompileStatic
          void printProgress(Map<Integer, Closure<String>> markers, int i) {
              for (e in markers.entrySet()) {
                  if (i%e.key==0) { print e.value(i) ; break }
              }
          }
      }
      

      Fails to compile with: Groovyc: [Static type checking] - Cannot find matching method java.util.Map$Entry#value(int). Please check if the declared type is right and if the method exists.

      The following fixes the problem, though it should not be necesarry to do explicit 'call'.

      class Test {
          @CompileStatic
          void printProgress(Map<Integer, Closure<String>> markers, int i) {
              for (e in markers.entrySet()) {
                  print e.value.call(i)
              }
          }
      }
      

      For comparison, the following passes:

      class Test {
          @CompileStatic
          void printProgress(Set<Closure<String>> markers, int i) {
              for (e in markers) {
                  print e(i)
              }
          }
      }
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              ddimitrov Dimitar Dimitrov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: