Description
Groovy 4.0.3 fails to compile this code:
@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) } }
It produces an error message like the following:
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
Explicitly typing i as InvocationMock makes the code compile.