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

STC: regression for instanceof on generic field/property

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.0, 2.5.10, 3.0.1, 3.0.2
    • Fix Version/s: 4.0.0-alpha-1, 3.0.3, 2.5.14
    • Component/s: None
    • Labels:
      None

      Description

      Consider the following:

      interface Face {
      }
      class Impl implements Face {
          String something
      }
      @groovy.transform.CompileStatic // or TypeChecked
      class Task<R extends Face> implements java.util.concurrent.Callable<String> {
          R request
      
          @Override
          String call() {
              if (request instanceof Impl) {
                  def thing = request.something // No such property: something for class: R
                  def lower = thing.toLowerCase()
              } else {
                  // ...
                  return null
              }
          }
      }
      def task = new Task<Impl>(request: new Impl(something: 'Hello World'))
      assert task.call() == 'hello world'
      

      Groovy 2.5.9 had flow-type support for "instanceof Impl", so no compiler error for "request.something" (which comes from Impl). This also affects Groovy 3, so I think the recent generics backport has something to do with it.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                emilles Eric Milles
                Reporter:
                emilles Eric Milles
              • 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