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

STC: UnionTypeClassNode created for simple instanceof scenarios

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 3.0.7, 4.0.0-alpha-2, 2.5.15
    • None
    • None

    Description

      Consider the following:

      interface A {
        def foo() {}
      }
      interface B extends A {
        def bar() {}
      }
      @groovy.transform.CompileStatic
      void test(A a) {
        if (a instanceof B) {
          a.foo()
          a.bar()
        }
      }
      

      Variable expression "a" infers to "<UnionType:A+B>" due to instanceof screening. Since B extends A, a simple ClassNode for B should be sufficient.

      The union types are harder to deal with for consumers. This is a variant of GROOVY-7333.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              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 - 40m
                  40m