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 2022/11/27 20:11:00 UTC

[jira] [Resolved] (GROOVY-6429) flow typing detects unexpected error at if-else flow

     [ https://issues.apache.org/jira/browse/GROOVY-6429?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Milles resolved GROOVY-6429.
---------------------------------
    Fix Version/s: 5.0.0-alpha-1
       Resolution: Fixed

https://github.com/apache/groovy/commit/f348e50481c24f21413c4d2b52b501b433003051

> flow typing detects unexpected error at if-else flow
> ----------------------------------------------------
>
>                 Key: GROOVY-6429
>                 URL: https://issues.apache.org/jira/browse/GROOVY-6429
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 2.2.0-rc-2, 2.3.0, 2.4.0-beta-3
>            Reporter: UEHARA Junji
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 5.0.0-alpha-1
>
>
> In groovy 2.2.0-rc-3, this code:
> {code}
> class A{
> }
> class B extends A{
>     void foo(){}
> }
> @groovy.transform.TypeChecked
> void test1(A x) {
>     if (x instanceof B) {
>         x.foo()
>     }
> }
> @groovy.transform.TypeChecked
> void test2(A x) {
>     if (!(x instanceof B)) {
>         return
>     }
>     x.foo()
> }
> @groovy.transform.TypeChecked
> void test3(A x) {
>     if (!(x instanceof B)) {
>         return
>     }
>     else {
>         x.foo()
>     }
> }
> @groovy.transform.TypeChecked
> void test4(A x) {
>     if (!(x instanceof B)) {
>         return
>     }
>     assert x instanceof B
>     x.foo()
> }
> test1(new B())
> test2(new B())
> test3(new B())
> test4(new B())
> {code}
> expects all OK. but test2 and test3 results in:
> {quote}
> % groovy a.groovy
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> /Users/uehaj/work/201311/comprehension_groovy/a.groovy: 19: [Static type checking] - Cannot find matching method A#foo(). Please check if the declared type is right and if the method exists.
>  @ line 19, column 5.
>        x.foo()
>        ^
> /Users/uehaj/work/201311/comprehension_groovy/a.groovy: 28: [Static type checking] - Cannot find matching method A#foo(). Please check if the declared type is right and if the method exists.
>  @ line 28, column 9.
>            x.foo()
>            ^
> 2 errors
> {quote}



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