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

@CompileStatic incorrectly inferred closure return type upper bound

    XMLWordPrintableJSON

Details

    Description

      @CompileStatic
      class Test<T> {
          def map(Closure<T> mapper) { }
      
          def failing(Closure<Boolean> predicate) {
              map { T it -> return predicate(it) ? it : null }
          }
          
          def passing(Closure<Boolean> predicate) {
              map { T it -> return predicate(it) ? it : (T) null }
          }
      
          def failingWithExplicitCast(Closure<Boolean> predicate) {
              Closure<T> c = { T it -> return predicate(it) ? it : null }
              map(c)
          }
      }
      

      In the last case, I would expect the compiler to obey the forced cast even at the risk of producing class-cast exception at runtime.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            ddimitrov Dimitar Dimitrov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: