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

Eric Milles edited comment on GROOVY-10792 at 10/25/22 8:04 PM:
----------------------------------------------------------------

{{ClosureWriter}} does this, so it requires STC or SC to make it work:
{code:java}
        // GROOVY-9971: closure return type is mapped to Groovy cast by classgen
        ClassNode returnType = expression.getNodeMetaData(INFERRED_RETURN_TYPE);
        if (returnType == null) returnType = ClassHelper.OBJECT_TYPE; // not 
STC or unknown path
{code}

You can do "!!buffer" or "(boolean) buffer" or "buffer as boolean" or 
"!buffer.isEmpty()".


was (Author: emilles):
{{ClosureWriter}} does this, so it requires STC or SC to make it work:
{code:java}
        // GROOVY-9971: closure return type is mapped to Groovy cast by classgen
        ClassNode returnType = expression.getNodeMetaData(INFERRED_RETURN_TYPE);
        if (returnType == null) returnType = ClassHelper.OBJECT_TYPE; // not 
STC or unknown path
{code}

You can do "!!buffer" or "(boolean) buffer" or "buffer as boolean".

> Declared generic parameter on method not transferred to Closure
> ---------------------------------------------------------------
>
>                 Key: GROOVY-10792
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10792
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 4.0.6
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Minor
>
> This is probably a duplicate, but I'm not sure which of.
> I'm using Awaitility's {{until(Callable<Boolean>)}} and passing it a closure:
> {code:groovy}
> List<String> buffer = []
> ...
> await().until { buffer }
> {code}
> Expected behavior: {{buffer}} is coerced to a boolean using Groovy truth.
> Actual behavior: 
> {code}
> java.lang.ClassCastException: class java.util.ArrayList cannot be cast to 
> class java.lang.Boolean
> {code}



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

Reply via email to