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

Cannot infer the right type in the presence of diamond operator

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.7
    • Fix Version/s: 4.0.0-alpha-3
    • Component/s: Static Type Checker
    • Labels:
      None

      Description

      Given the following program

      class Foo<T> {
          T f;
          Foo (T f) {
            this.f = f;
          }
      }
      
      class Main  {
        public static void main(String[] args) {
            Foo<Integer> x = new Foo<>(1);
            assert x.f < 10 == true; // does not compile
            m(x);
        }  public static void m(Foo<Integer> x) {
            assert x.f < 10 == true; // compiles fine
        }
      }
      

      the type checker reports:

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Test.groovy: 11: [Static type checking] - Cannot find matching method java.lang.Object#compareTo(int). Please check if the declared type is correct and if the method exists.
       @ line 11, column 14.
               assert x.f < 10 == true;
                      ^1 error
      
      

      Expected behaviour

      I would expected that the program above compiles successfully.

        Attachments

          Activity

            People

            • Assignee:
              emilles Eric Milles
              Reporter:
              theosot Thodoris Sotiropoulos
            • Votes:
              0 Vote for this issue
              Watchers:
              1 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 - 0.5h
                0.5h