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/06/29 18:05:00 UTC

[jira] [Assigned] (GROOVY-10673) STC inferred type lost in nested closure

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

Eric Milles reassigned GROOVY-10673:
------------------------------------

    Assignee: Eric Milles

> STC inferred type lost in nested closure
> ----------------------------------------
>
>                 Key: GROOVY-10673
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10673
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.3
>            Reporter: Jan Hackel
>            Assignee: Eric Milles
>            Priority: Major
>
> Groovy 4.0.3 fails to compile this code:
>  
> {code:groovy}
> @Grab('org.mockito:mockito-core:4.5.1')
> @Grab('org.junit.jupiter:junit-jupiter-api:5.8.2')
> import groovy.transform.CompileStatic
> import org.junit.jupiter.api.Test
> import org.mockito.Mockito
> import static org.mockito.ArgumentMatchers.anyString
> import static org.mockito.Mockito.when
> @CompileStatic
> class MockitoAnswerTest {
>   @Test
>   void stubbing() {
>     def a = Mockito.mock(A)
>     when(a.f(anyString())).thenAnswer { i ->
>       new B().tap {
>         b = 'Hallo' + i.arguments[0]
>       }
>     }
>     assert a.f('x') != null
>   }
>   static class B {
>     String b
>   }
>   interface A {
>     B f(String x)
>   }
> }
> {code}
> It produces an error message like the following:
> {noformat}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> /home/jh/Code/groovy-bugs/src/test/groovy/de/jhunovis/fluentapi/MockitoAnswerTest.groovy: 20: [Static type checking] - No such property: arguments for class: java.lang.Object
>  @ line 20, column 24.
>            b = 'Hallo' + i.arguments[0]
>                           ^
> /home/jh/Code/groovy-bugs/src/test/groovy/de/jhunovis/fluentapi/MockitoAnswerTest.groovy: 20: [Static type checking] - Cannot find matching method java.lang.Object#getAt(int). Please check if the declared type is correct and if the method exists.
>  @ line 20, column 23.
>            b = 'Hallo' + i.arguments[0]
>                          ^
> 2 errors
> {noformat}
>  
> Explicitly typing {{i}} as {{InvocationMock}} makes the code compile.



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