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/06/04 13:38:00 UTC

[jira] [Assigned] (GROOVY-11397) Regression in SAM parameter type checking

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

Eric Milles reassigned GROOVY-11397:
------------------------------------

    Assignee: Eric Milles

> Regression in SAM parameter type checking
> -----------------------------------------
>
>                 Key: GROOVY-11397
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11397
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 3.0.18, 3.0.19, 3.0.20, 3.0.21
>            Reporter: Octavia Togami
>            Assignee: Eric Milles
>            Priority: Minor
>
> A regression in 3.0.18, possibly related to https://issues.apache.org/jira/browse/GROOVY-11013, causes the following code to no longer compile:
> {code:java}
> @groovy.transform.CompileStatic
> class TestClass {
>     interface Action<T> { void run(T t); }
>     interface Exec { void doSomething(); }
>     private Exec configExec(Action<Exec> action) { return null; }
>     private Exec createExec() {
>         return configExec({ Exec it ->
>             it.doSomething()
>         } as Action)
>     }   
> }
> {code}
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> TestClass.groovy: 11: [Static type checking] - Cannot find matching method java.lang.Object#doSomething(). Please check if the declared type is correct and if the method exists.
>  @ line 11, column 13.
>                it.doSomething()
>                ^
> 1 error
> {code}
> It appears that for some reason, the cast to `Action` is overriding the more explicit type of the parameter, resulting in `it` now having the type of `Object`. Changing the cast to be `as Action<Exec>` fixes the problem.



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