Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
Consider the following:
@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
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.
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)