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

Type-inference fails for tap on inner classes with type checking

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.9
    • 3.0.0
    • None
    • None
    • Groovy 2.5.9. on Zulu JDK 11.0.3; Linux

    Description

      The following code will not compile with Groovy 2.5.9. It produces an error "[Static type checking] - Cannot assign value of type java.lang.Object to variable of type java.time.LocalDate". Same thing happens for instance fields.

      A workaround is to qualify the source field either by this or by class name.

      import groovy.transform.CompileStatic
      import java.time.LocalDate
      
      @CompileStatic
      class TapTypeChecking {
      
        private static final LocalDate DATE = LocalDate.of(2020, 2, 1)
      
        static Inner inner() {
          return new Inner().tap {
            someDate = DATE
          }
        }
      
        static class Inner {
      
          LocalDate someDate
        }
      }
      

      Attachments

        Activity

          People

            emilles Eric Milles
            jhunovis Jan Hackel
            Votes:
            0 Vote for this issue
            Watchers:
            2 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 - 10m
                10m