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

Eric Milles resolved GROOVY-11480.
----------------------------------
    Fix Version/s: 5.0.0-alpha-11
       Resolution: Fixed

https://github.com/apache/groovy/commit/59b02b54d8d8458b4be6bc2f1f16c641ae077def

> Cast exception when using qualified this in lambda
> --------------------------------------------------
>
>                 Key: GROOVY-11480
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11480
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 5.0.0-alpha-11
>
>
> Consider the following:
> {code:groovy}
> @groovy.transform.CompileStatic
> class Test1 {
>     class Test2 {
>         def m() {
>             Optional.empty().orElseGet(() -> Test1.this.n)
>         }
>     }
>     private n = 123
> }
> assert new Test1.Test2(new Test1()).m() == 123
> {code}
> The expression "Test1.this.n" is not detected as an instance member access.  
> Thus the thisObject reference for the lambda class is set to {{Class<Test2>}} 
> and this results in a cast exception at runtime.
> {code}
> java.lang.ClassCastException: class java.lang.Class cannot be cast to class 
> Test1$Test2 (java.lang.Class is in module java.base of loader 'bootstrap'; 
> Test1$Test2 is in unnamed module of loader 
> groovy.lang.GroovyClassLoader$InnerLoader @7ec68821)
>         at Test1$Test2$_m_lambda1.doCall(TestScript85.groovy:5)
>         at java.base/java.util.Optional.orElseGet(Optional.java:364)
>         at Test1$Test2.m(TestScript85.groovy:5)
> {code}



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

Reply via email to