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/03/31 01:36:00 UTC
[jira] [Resolved] (GROOVY-10557) TypeChecked/CompileStatic tries to cast to wrong type in nested closure
[ https://issues.apache.org/jira/browse/GROOVY-10557?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-10557.
----------------------------------
Fix Version/s: 3.0.11
Resolution: Fixed
https://github.com/apache/groovy/commit/d37a59341154bd0d02937621d11ee90b983837c1
> TypeChecked/CompileStatic tries to cast to wrong type in nested closure
> -----------------------------------------------------------------------
>
> Key: GROOVY-10557
> URL: https://issues.apache.org/jira/browse/GROOVY-10557
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 3.0.9, 2.5.16, 3.0.10
> Reporter: Leonard Brünings
> Assignee: Eric Milles
> Priority: Major
> Fix For: 3.0.11
>
>
> The code
> {code:groovy}
> import groovy.transform.*
> import java.util.function.Function
> @CompileStatic
> class Foo {
>
> final <T> T foo(Function<Reader, T> function) {
> new StringReader("").withCloseable { reader ->
> function.apply(reader)
> }
> }
>
> static void main(String... args) {
> println new Foo().foo { it.text.empty }
> }
> }
> {code}
> fails with
> {noformat}
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'true' with class 'java.lang.Boolean' to class 'java.io.StringReader'
> at Foo$_foo_closure1.doCall(Script1.groovy:10)
> at Foo$_foo_closure1.call(Script1.groovy)
> at Foo.foo(Script1.groovy:9)
> at Foo.main(Script1.groovy:15)
> {noformat}
> while it works fine with {{{}@CompileDynamic{}}}. As far as I can see this regression was introduced with 3.0.9.
> (see [Groovy Web Console|https://gwc-experiment.appspot.com/?g=groovy_3_0&codez=eJxFj19uwjAMxp-bU1g8tdPmEyA0CYkDDC5gStJ5SuMoMWUV6t0p_QN-sCx_9uefuY2SFJok0vWoiUJ2klr8MDwrf9QRXpU9umuolSXgYSmMMd97aSN7e1RSrk3tKWc4iMDdwBhTchzIw_a0gxM4kXJd3_5Yutj0CaOyelewbD4j2BscNXFo5slys6nwxvq795Itnb2FO6RJgq-dKYrihUgx-r6cteplOKzF1BneiHnCh074Ai1xKOeziAiUmly9oeLYVx9muPHRskL3fBdYUe2_om2j9ov3YAbzANehbJM] as long as deployed version is 3.0.10)
--
This message was sent by Atlassian Jira
(v8.20.1#820001)