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 2024/01/18 21:59:00 UTC

[jira] [Created] (GROOVY-11290) STC: multiple instanceof checks produce different results

Eric Milles created GROOVY-11290:
------------------------------------

             Summary: STC: multiple instanceof checks produce different results
                 Key: GROOVY-11290
                 URL: https://issues.apache.org/jira/browse/GROOVY-11290
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
    Affects Versions: 4.0.18
            Reporter: Eric Milles


Consider the following:
{code:groovy}
@groovy.transform.TypeChecked test1(CharSequence chars) {
  if (chars instanceof Cloneable && chars instanceof Closeable) {
      chars
  }
}
@groovy.transform.TypeChecked test2(CharSequence chars) {
  if (chars instanceof Cloneable) {
    if (chars instanceof Closeable) {
      chars
    }
  }
}
{code}

The last occurrence of "chars" in {{test1}} has the inferred type "CharSequence & Cloneable & Closeable".  However the last occurrence of "chars" in {{test2}} has the inferred type "CharSequence & Closeable" instead of the expected result like {{test1}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)