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

Variables which type is determined thanks to instanceof checks should be usable as arguments without casts

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0-beta-2
    • 2.0-beta-3
    • Static Type Checker
    • None

    Description

      The current implementation of the type checker allows to use methods of an object without the need of an explicit cast if it is wrapped in a proper instanceof check:

      class A {
         void foo() {}
      }
      def o
      ...
      if (o instanceof A) {
         o.foo()
      }
      

      But it doesn't work if the object is used as an argument:

      class A {}
      void m(A a) { ... }
      def o
      ...
      if (o instanceof A) {
         m(o) // requires m((A) o) which should not be necessary
      }
      

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              melix Cédric Champeau
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: