[jira] [Commented] (GROOVY-7558) Error when referencing private member variables from within a closure

2016-07-02 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on GROOVY-7558:


Github user asfgit closed the pull request at:

https://github.com/apache/groovy/pull/242


> Error when referencing private member variables from within a closure
> -
>
> Key: GROOVY-7558
> URL: https://issues.apache.org/jira/browse/GROOVY-7558
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.4
> Environment: Linux x86-64 / java 1.8.0_60
>Reporter: Jon Keys
>Assignee: Shil Sinha
>
> Originally posted on SO here: 
> http://stackoverflow.com/questions/32212260/in-groovy-is-it-legal-to-reference-private-member-variables-from-within-a-closur
> The code below fails with {{java.lang.ClassCastException: 
> Test$_doStuff_closure1 cannot be cast to Test}}.  Interestingly, if I remove 
> the {{@CompileStatic}} annotation or make the member variable non-private it 
> works as expected.
> {code:java}
> class Test {
> private String str = "hi"
> @groovy.transform.CompileStatic
> public void doStuff() {
> Closure c = {
> println str
> }
> c()
> }
> }
> new Test().doStuff()
> {code}
> It also works when {{@CompileStatic}} is moved up to the class level
> {code:java}
> @groovy.transform.CompileStatic
> class Test {
> private String str = "hi"
> public void doStuff() {
> Closure c = {
> println str
> }
> c()
> }
> }
> new Test().doStuff()
> {code}



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


[jira] [Commented] (GROOVY-7558) Error when referencing private member variables from within a closure

2016-01-19 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on GROOVY-7558:


Github user shils commented on a diff in the pull request:

https://github.com/apache/groovy/pull/242#discussion_r50188030
  
--- Diff: 
src/main/org/codehaus/groovy/transform/sc/StaticCompilationVisitor.java ---
@@ -123,9 +123,20 @@ public void visitClass(final ClassNode node) {
 }
 super.visitClass(node);
 addPrivateFieldAndMethodAccessors(node);
+if (isStaticallyCompiled(node)) {
+ClassNode outer = node.getOuterClass();
+if (outer != null && !isStaticallyCompiled(outer)) {
+
outer.putNodeMetaData(StaticCompilationMetadataKeys.DYNAMIC_OUTER_NODE, true);
+}
+}
 classNode = oldCN;
 }
 
+public void visitDynamicOuterClass(ClassNode node) {
--- End diff --

adding a public method here is not ideal, though it seems like the 
alternative would be to create a separate class responsible for adding bridge 
methods, which would be used by StaticCompilationVisitor as well as the phase 
operation added for dynamic outer classes.


> Error when referencing private member variables from within a closure
> -
>
> Key: GROOVY-7558
> URL: https://issues.apache.org/jira/browse/GROOVY-7558
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.4
> Environment: Linux x86-64 / java 1.8.0_60
>Reporter: Jon Keys
>Assignee: Cédric Champeau
>
> Originally posted on SO here: 
> http://stackoverflow.com/questions/32212260/in-groovy-is-it-legal-to-reference-private-member-variables-from-within-a-closur
> The code below fails with {{java.lang.ClassCastException: 
> Test$_doStuff_closure1 cannot be cast to Test}}.  Interestingly, if I remove 
> the {{@CompileStatic}} annotation or make the member variable non-private it 
> works as expected.
> {code:java}
> class Test {
> private String str = "hi"
> @groovy.transform.CompileStatic
> public void doStuff() {
> Closure c = {
> println str
> }
> c()
> }
> }
> new Test().doStuff()
> {code}
> It also works when {{@CompileStatic}} is moved up to the class level
> {code:java}
> @groovy.transform.CompileStatic
> class Test {
> private String str = "hi"
> public void doStuff() {
> Closure c = {
> println str
> }
> c()
> }
> }
> new Test().doStuff()
> {code}



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


[jira] [Commented] (GROOVY-7558) Error when referencing private member variables from within a closure

2016-01-16 Thread ASF GitHub Bot (JIRA)

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

ASF GitHub Bot commented on GROOVY-7558:


GitHub user shils opened a pull request:

https://github.com/apache/groovy/pull/242

GROOVY-7558 Add private field accessors and bridge methods to dynamic…

… classes with statically compiled inner classes

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/shils/groovy GROOVY-7558

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/groovy/pull/242.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 #242


commit 5cb6368ed7c5755c62a76431e96b944e3dee796e
Author: Shil S 
Date:   2015-10-11T19:58:52Z

GROOVY-7558 Add private field accessors and bridge methods to dynamic 
classes with statically compiled inner classes




> Error when referencing private member variables from within a closure
> -
>
> Key: GROOVY-7558
> URL: https://issues.apache.org/jira/browse/GROOVY-7558
> Project: Groovy
>  Issue Type: Bug
>  Components: Static compilation
>Affects Versions: 2.4.4
> Environment: Linux x86-64 / java 1.8.0_60
>Reporter: Jon Keys
>Assignee: Cédric Champeau
>
> Originally posted on SO here: 
> http://stackoverflow.com/questions/32212260/in-groovy-is-it-legal-to-reference-private-member-variables-from-within-a-closur
> The code below fails with {{java.lang.ClassCastException: 
> Test$_doStuff_closure1 cannot be cast to Test}}.  Interestingly, if I remove 
> the {{@CompileStatic}} annotation or make the member variable non-private it 
> works as expected.
> {code:java}
> class Test {
> private String str = "hi"
> @groovy.transform.CompileStatic
> public void doStuff() {
> Closure c = {
> println str
> }
> c()
> }
> }
> new Test().doStuff()
> {code}
> It also works when {{@CompileStatic}} is moved up to the class level
> {code:java}
> @groovy.transform.CompileStatic
> class Test {
> private String str = "hi"
> public void doStuff() {
> Closure c = {
> println str
> }
> c()
> }
> }
> new Test().doStuff()
> {code}



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