[jira] [Commented] (GROOVY-7970) Can't call private method from outer class when using anonymous inner classes and @CS
[ https://issues.apache.org/jira/browse/GROOVY-7970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15655265#comment-15655265 ] Paul King commented on GROOVY-7970: --- Even though this is a bug fix, the fix relies on several other changes that have only happened on the 2.5 branch (current master). It could be back-ported but will be a little tedious and require some work. Is it important to have this fix in the 2_4_X branch? > 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 >Assignee: Paul King > > 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)
[jira] [Commented] (GROOVY-7970) Can't call private method from outer class when using anonymous inner classes and @CS
[ https://issues.apache.org/jira/browse/GROOVY-7970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15615142#comment-15615142 ] ASF GitHub Bot commented on GROOVY-7970: GitHub user paulk-asert opened a pull request: https://github.com/apache/groovy/pull/452 GROOVY-7970: Can't call private method from outer class when using anonymous inner classes and @CS Not a final solution. This fixes public methods. Private/protected methods are handled by a different code path which isn't yet fixed. You can merge this pull request into a Git repository by running: $ git pull https://github.com/paulk-asert/groovy groovy7970 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/452.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #452 commit b75907f844f0abb44414ee3e53e9bb247ee33a55 Author: paulkDate: 2016-10-25T04:30:08Z GROOVY-7970: Can't call private method from outer class when using anonymous inner classes and @CS (allow through the type checker) commit 63e55bbd79a1fa5318feaf08c43ac9e86e9c0593 Author: paulk Date: 2016-10-28T11:27:24Z GROOVY-7970: Can't call private method from outer class when using anonymous inner classes and @CS > 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)
[jira] [Commented] (GROOVY-7970) Can't call private method from outer class when using anonymous inner classes and @CS
[ https://issues.apache.org/jira/browse/GROOVY-7970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15611586#comment-15611586 ] Paul King commented on GROOVY-7970: --- I think it probably should - but I'll work on that more tomorrow and see if any ugly cases come up. It is always tricky with closures since they are so flexible, you can't make as many assumptions about what they would definitely produce. The type checking extension mechanism is in place for that purpose. If we can't be certain what should happen we should leave it out of the main compilation path. > 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)
[jira] [Commented] (GROOVY-7970) Can't call private method from outer class when using anonymous inner classes and @CS
[ https://issues.apache.org/jira/browse/GROOVY-7970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15611555#comment-15611555 ] Graeme Rocher commented on GROOVY-7970: --- Great news! I guess we need to work out if the former case should be allowed > 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)
[jira] [Commented] (GROOVY-7970) Can't call private method from outer class when using anonymous inner classes and @CS
[ https://issues.apache.org/jira/browse/GROOVY-7970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15611543#comment-15611543 ] Paul King commented on GROOVY-7970: --- After applying the proposed PR#451 from GROOVY-7973 and also convincing the type checker to allow Class.this type expressions within closures, the following script works (i.e. the above suggested workaround which was showing a VerifyError): {code} @groovy.transform.CompileStatic class Bar { String renderTemplate(String arg) { "dummy$arg" } def foo() { new Object() { String bar() { 'B'.with{ Bar.this.renderTemplate(it) } } } } } assert new Bar().foo().bar() == 'dummyB' {code} I still need to work on the fix without the qualified name workaround in place. > 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)
[jira] [Commented] (GROOVY-7970) Can't call private method from outer class when using anonymous inner classes and @CS
[ https://issues.apache.org/jira/browse/GROOVY-7970?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15576333#comment-15576333 ] Paul King commented on GROOVY-7970: --- A slightly simpler example (and indicating that it isn't just private methods):: {code} @groovy.transform.CompileStatic class Bar { void renderTemplate() { } def foo() { new Object() { String toString() { [].any { renderTemplate() } } } } } new Bar().foo() {code} > 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)