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

STC: outer class type parameter inference

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 4.0.5
    • Static Type Checker
    • None

    Description

      Consider the following (extracted from mybatis SelectDSLCompleter):

      class Model {
      }
      interface Output<T> {
        T build()
      }
      abstract class Input<T> extends QueryDSL<Inner> implements Output<T> {
        class Inner implements Output<T> {
          @Override T build() { }
        }
      }
      
      abstract class QueryDSL<X> {
        abstract X where()
      }
      
      @FunctionalInterface
      interface Func extends Function<Input<Model>, Output<Model>> {
      }
      
      void select(Func func) {
      }
      
      @groovy.transform.TypeChecked
      void test() {
        select { input -> input.where() } // Cannot return value of type Inner for closure expecting Output<Model>
      }
      

      "input" is inferred correctly to be of type "Input<Model>" which should lead to an "Inner" return type for "where()" that implements "Output<Model>". Some context is lost along the way and "Output<Object>" is inferred instead.

      https://github.com/groovy/groovy-eclipse/issues/1364

      Attachments

        Activity

          People

            emilles Eric Milles
            emilles Eric Milles
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: