You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/10/03 16:06:00 UTC

[jira] [Created] (GROOVY-9769) STC: UnionTypeClassNode created for simple instanceof scenarios

Eric Milles created GROOVY-9769:
-----------------------------------

             Summary: STC: UnionTypeClassNode created for simple instanceof scenarios
                 Key: GROOVY-9769
                 URL: https://issues.apache.org/jira/browse/GROOVY-9769
             Project: Groovy
          Issue Type: Bug
            Reporter: Eric Milles
            Assignee: Eric Milles


Consider the following:
{code:groovy}
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()
  }
}
{code}

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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)