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/09/06 17:25:00 UTC

[jira] [Resolved] (GROOVY-11471) Assignments in closures can introduce issues in flow typing

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

Eric Milles resolved GROOVY-11471.
----------------------------------
    Fix Version/s: 5.0.0-alpha-10
       Resolution: Fixed

https://github.com/apache/groovy/commit/092c0c0769a03a952d7337719b5097943ed78c4c

> Assignments in closures can introduce issues in flow typing
> -----------------------------------------------------------
>
>                 Key: GROOVY-11471
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11471
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>             Fix For: 5.0.0-alpha-10
>
>
> I have the following program
> {code:java}
> class Test {
>   public static void main(String[] args) {
>     def x = 1
>     Closure m = null
>     if (true) {
>       m = {x = ""}
>     }
>     x = 1
>     m()
>   }
> } {code}
> h3. Actual behavior
> The code compiles, but I get ClassCastException at runtime
> {code:java}
>  Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '' with class 'java.lang.String' to class 'java.lang.Integer'
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177)
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:294)
>         at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:248)
>         at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336)
>         at Test$_main_closure1.doCall(test.groovy:6)
>         at Test$_main_closure1.call(test.groovy)
>         at Test.main(test.groovy:9)
> {code}
> h3. Expected behavior
> The code should have been rejected.



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