You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/06/08 09:18:00 UTC

[jira] [Updated] (GROOVY-10080) Closure with type argument inference does not work as expected

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

Stefanos Chaliasos updated GROOVY-10080:
----------------------------------------
    Component/s: Static Type Checker
                 Static compilation

> Closure with type argument inference does not work as expected
> --------------------------------------------------------------
>
>                 Key: GROOVY-10080
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10080
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>            Reporter: Stefanos Chaliasos
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-1
>
>
> I have the following Groovy program.
> {code:groovy}
> @groovy.transform.CompileStatic
> public class Main {
>   public static void main(String[] args) {
>     def closure = {
>       new Bar<>(new Foo<Long>());
>     }
>     closure().f.m(new BigDecimal[0]) // this doesn't work
>     // the following works
>     // Bar<Foo<Long>> x = closure()
>     // x.f.m(new BigDecimal[0]);
>   }
> }
> class Foo<X> {
>   void m(Object[] x) {}
> }
> class Bar<X> {
>   X f;
>   Bar(X f) {
>     this.f = f;
>   }
> }
> class Baz {}
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Main.groovy: 7: [Static type checking] - Cannot find matching method java.lang.Object#m(java.math.BigDecimal[]). Please check if the declared type is correct and if the method exists.
>  @ line 7, column 5.
>        closure().f.m(new BigDecimal[0]) 
>        ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Affected Version
> This programs fails when compiled with the compiler from the master (commit: a8023b1b0d1d79800677ce2b4665ee3fb14688f4) and with 4.0.0-alpha-2.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)