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

Paul King edited comment on GROOVY-7970 at 10/15/16 9:02 PM:
-------------------------------------------------------------

A slightly simpler example (and indicating that it isn't just private methods)::
{code}
@groovy.transform.CompileStatic
class Bar {
    String renderTemplate(String arg) { "dummy$arg" }
    def foo() {
        'A'.with{ renderTemplate(it) } // OK if not in inner class
        new Object() {
            String toString() {
               //'B'.with{ renderTemplate(it) }
               renderTemplate('C') // OK if not within closure
            }
        }
    }
}

new Bar().foo()
{code}
which has this error:
{noformat}
[Static type checking] - Cannot find matching method 
Bar$1#renderTemplate(java.lang.String). Please check if the declared type is 
right and if the method exists.
{noformat}


was (Author: paulk):
A slightly simpler example (and indicating that it isn't just private methods)::
{code}
@groovy.transform.CompileStatic
class Bar {
    String renderTemplate(String arg) { "dummy$arg" }
    def foo() {
        //['A', 'B'].collect{ renderTemplate(it) }.join('|') // OK if not in 
inner class
        new Object() {
            String toString() {
               ['C', 'D'].collect{ renderTemplate(it) }.join('|')
               //renderTemplate('E') // OK if not within closure
            }
        }
    }
}

new Bar().foo()
{code}
which has this error:
{noformat}
[Static type checking] - Cannot find matching method 
Bar$1#renderTemplate(java.lang.String). Please check if the declared type is 
right and if the method exists.
{noformat}

> Can't call private method from outer class when using anonymous inner classes 
> and @CS
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7970
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7970
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.7
>            Reporter: Graeme Rocher
>
> This example:
> {code}
> import groovy.json.*
> import groovy.transform.*
> @CompileStatic
> class Bar {
>     private Writable renderTemplate(Object o, Map args) {
>     
>     }
>     def foo(Map map, Map arguments) {
>     
>         def writable = new Writable() {
>             @Override
>             Writer writeTo(Writer out) throws IOException {
>                 StreamingJsonBuilder builder = new StreamingJsonBuilder(out)
>                 builder.call {
>                     for(key in map.keySet()) {
>                         def o = map.get(key)
>                         Writable writable = renderTemplate((Object)o, 
> arguments)
>                         call(key.toString(), writable)
>                     }
>                 }
>                 return out
>             }
>         }
>     }
> }
> writable = new Bar().foo([one:'two'],[foo:'bar'])
> sw = new StringWriter()
> writable.writeTo(sw)
> println sw
> {code}
> Results in a compilation error:
> {code}
> [Static type checking] - Cannot find matching method 
> Bar$1#renderTemplate(java.lang.Object, java.util.Map). Please check if the 
> declared type is right and if the method exists.
>  at line: 18, column: 45
> {code}
> If you attempt to use {{Bar.this}}:
> {code}
> Writable writable = Bar.this.renderTemplate((Object)o, arguments)
> {code}
> The result is a VerifierError
> {code}
> java.lang.VerifyError: (class: Bar$1$_writeTo_closure1, method: doCall 
> signature: (Ljava/lang/Object;)Ljava/lang/Object;) Incompatible argument to 
> function
>       at Bar$1.writeTo(ConsoleScript11:15)
>       at groovy.lang.Writable$writeTo.call(Unknown Source)
>       at 
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
>       at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
>       
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to