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 2021/10/25 16:50:00 UTC

[jira] [Resolved] (GROOVY-7490) CompileStatic confuses statically importing an instance and statically importing a method

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

Eric Milles resolved GROOVY-7490.
---------------------------------
    Fix Version/s: 4.0.0-beta-2
       Resolution: Fixed

https://github.com/apache/groovy/commit/56fd1b05eaf9ee7d53ce743ded0afa4677d1810b

{code:groovy}
import static WithCall.callable_property

class WithCall {
  static final WithCall callable_property = new WithCall()
  String call(String input) {
    return input
  }
}

@groovy.transform.CompileStatic
void test7490() {
  print callable_property('works')
}

test7490()
{code}

> CompileStatic confuses statically importing an instance and statically importing a method
> -----------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7490
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7490
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation
>    Affects Versions: 2.4.3
>            Reporter: Robert Elliot
>            Assignee: Eric Milles
>            Priority: Major
>             Fix For: 4.0.0-beta-2
>
>
> When statically importing a field and immediately calling a call() method on it, the static compiler gets confused and looks for a static method with the name of the field that takes the arguments passed to the call() method.
> See below - comment out @CompileStatic and it will run as expected.
> {code:java}
> import groovy.transform.CompileStatic
> class WithCall {
>     static final WithCall staticallyImported = new WithCall()
>     String call(String input) {
>         return input;
>     }
> }
> class CompileStaticImport {
>     @CompileStatic
>     public static void main(String[] args) {
>         assert WithCall.staticallyImported("to print") == "to print"
>     }
> }
> {code}
> Error:(16, 16) Groovyc: [Static type checking] - Cannot find matching method WithCall#staticallyImported(java.lang.String). Please check if the declared type is right and if the method exists.



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