[ 
https://issues.apache.org/jira/browse/GROOVY-8202?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17341513#comment-17341513
 ] 

Eric Milles edited comment on GROOVY-8202 at 5/9/21, 2:06 PM:
--------------------------------------------------------------

For the test3 case, it is not void return that is considered.  There is a 
"return null" inserted because the code falls off the end before supplying the 
necessary return value.  This may be missing for the closure expression.


was (Author: emilles):
For the test3 case, it is not void return that is considered.  There is a 
"return null" inserted because the code falls off the end before supplying the 
necessary return value.  This may be missing for the closure expression.

test1() returns "asd" and test3() returns null.  I think that is evidence of 
the missing return for the closure.

> void tail calls in closures break @CompileStatic type inference
> ---------------------------------------------------------------
>
>                 Key: GROOVY-8202
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8202
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.10
>            Reporter: Joan Karadimov
>            Assignee: Eric Milles
>            Priority: Minor
>
> Consider this piece of code:
> {code:groovy}
> void f() {
> }
> @CompileStatic
> String test1() {
>       Closure<String> x = {
>               if (true) {
>                       "asd"
>               } else {
>                       f()
>                       null
>               }
>       }
>       x.call()
> }
> @CompileStatic
> String test2() {
>       Closure<String> x = { // Cannot assign Closure<Object> to 
> Closure<String>
>               if (true) {
>                       "asd"
>               } else {
>                       f()
>               }
>       }
>       x.call()
> }
> @CompileStatic
> String test3() {
>       if (true) {
>               "asd"
>       } else {
>               f()
>       }
> }
> {code}
> The code in _*test1*_ compiles correctly. The type of the closure in 
> _*test2*_ is inferred as _*Closure<Object>*_ and that results in a static 
> type checking error. There is an inconsistency here - in _*test3*_ the type 
> inference yields _*String*_.
> Basically - _*null*_ s are not considered when the type is inferred. Calls to 
> void methods should not be either.



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

Reply via email to