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 2020/09/17 22:39:00 UTC

[jira] [Resolved] (GROOVY-8103) STC: matching return type of one static method to parameter type of another

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

Eric Milles resolved GROOVY-8103.
---------------------------------
    Resolution: Fixed

Fixed circa 2.5.10.  I wasn't able to create a good enough test case to find out exactly when.

> 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
>            Priority: Major
>
> 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
(v8.3.4#803005)