[ https://issues.apache.org/jira/browse/GROOVY-8103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15999412#comment-15999412 ]
Eric Milles commented on GROOVY-8103: ------------------------------------- I have another example of this which is specific to CompileStatic. {{assertThat}} at the end of the block infers to the {{assertThat(Object): ObjectAssert}} overload. This is correct. Then {{isNotNull(Object)}} is defined in the superclass, which should now have generic parameters {{GenericAssert<ObjectAssert, Object>}}. And so {{isNotNull}} has a return type of the second first generic param {{ObjectAssert}}. But I am getting {{ThrowableAssert}} as the inferred return type. When I switch from CompileStatic to TypeChecked, the correct return type is inferenced. So there must be something in the extra transformations of static compilation that cause this. {code} @Grab('org.easytesting:fest-assert:1.4') import static org.fest.assertions.Assertions.assertThat import static org.mockito.Matchers.* import static org.mockito.Mockito.* import groovy.transform.CompileStatic import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.runners.MockitoJUnitRunner @CompileStatic @RunWith(MockitoJUnitRunner) final class MockTest { @Mock Sample sample @Test void testMocks() { when(sample.method(any(Object))).thenReturn(~/abc/) def pat = sample.pattern assertThat(pat).isNotNull() verify(sample).getPattern() } } {code} > STC: matching return type of one static method to parameter type of another > --------------------------------------------------------------------------- > > Key: GROOVY-8103 > URL: https://issues.apache.org/jira/browse/GROOVY-8103 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker > Reporter: Eric Milles > > We are using a fluent API based testing library (FEST assert). I tried to > boil this problem down; I hope this example is not too abstract. Basically, > there is a main fluent method that starts every test assertion and this is a > static method with many overloads. The library offers an extension mechanism > where you put in your own type and this is where the checker is failing. > {code} > @groovy.transform.TypeChecked > def method() { > fluent('string').isEqualTo('x') // fine > fluent(new Util.Ours()).isSimilarTo('') // fine > fluent(Util.Ours.factory('{}')).isSimilarTo('{"key":"val"}') // STC error > } > {code} > Supporting code (library provided): > {code} > class Fluent > { > static FluentAPI fluent(String s) { return new FluentAPI() } > static <T extends FluentExtension> T fluent(T t) { return t } > } > class FluentAPI > { > FluentAPI isEqualTo(String s) { return this } > } > interface FluentExtension > { > } > {code} > Our extension: > {code} > class Util { > static class Ours implements FluentExtension { > Ours isSimilarTo(String json) { return this } > } > static Ours factory(String json) { new Ours() } > } > {code} -- This message was sent by Atlassian JIRA (v6.3.15#6346)