groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert Elliot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GROOVY-7490) CompileStatic confuses statically importing an instance and statically importing a method
Date Fri, 03 Jul 2015 05:57:04 GMT

    [ https://issues.apache.org/jira/browse/GROOVY-7490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14612867#comment-14612867
] 

Robert Elliot commented on GROOVY-7490:
---------------------------------------

To me that's very unintuitive - in the example above if you pull out WithCall.staticallyImported
into a variable it all compiles.  Inline it and it stops compiling. Surely a compiler shouldn't
care whether a reference is inlined or not. 

(It's also stopping me producing a type safe DSL without resorting to the evils of delegate
backed closures.)

> 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: C├ędric Champeau
>
> 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
(v6.3.4#6332)

Mime
View raw message