[jira] [Commented] (GROOVY-8051) Reference outer class property within inner class closure

2020-06-07 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-8051:
-

This was resolved by the rewriting of "this" -> "thisObject" -> 
"thisObject.this$0" in Groovy 2.5: 
https://github.com/apache/groovy/blob/GROOVY_2_5_X/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticInvocationWriter.java#L376

GROOVY-7970 seems to be the source of the fix and includes discussion regarding 
backporting to Groovy 2.4.  GROOVY-8051 specifically can be fixed with only the 
"if (target.isPublic() && receiver != null)" block in 
StaticInvocationWriter#writeDirectMethodCall.

> Reference outer class property within inner class closure
> -
>
> Key: GROOVY-8051
> URL: https://issues.apache.org/jira/browse/GROOVY-8051
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler, Static compilation, Static Type Checker
>Affects Versions: 2.4.7, 2.4.8
>Reporter: Daniil Ovchinnikov
>Priority: Major
>
> {code}
> @CompileStatic // works without this @CompileStatic
> class Outer {
>   def foo = 1
>   Inner createInner() { new Inner() }
>   class Inner {
> Closure createClosure() {
>   return { foo }
> }
>   }
> }
> @CompileStatic
> class Main {
>   static void main(String[] args) {
> def i = new Outer().createInner()
> def cl = i.createClosure()
> println cl()
>   }
> }
> {code}
> Fail in runtime with:
> {noformat}
> Exception in thread "main" 
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
> Cannot cast object 'Outer$Inner@23e028a9' with class 'Outer$Inner' to class 
> 'Outer'
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
>   at 
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
>   at Outer$Inner$_createClosure_closure1.doCall(innerclassestest.groovy)
>   at Outer$Inner$_createClosure_closure1.call(innerclassestest.groovy)
>   at Main.main(innerclassestest.groovy:23)
> {noformat}



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


[jira] [Commented] (GROOVY-8051) Reference outer class property within inner class closure

2017-03-20 Thread Paul King (JIRA)

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

Paul King commented on GROOVY-8051:
---

I can reproduce on 2.4.10 but it seems fixed in 2.5+ snapshots.

> Reference outer class property within inner class closure
> -
>
> Key: GROOVY-8051
> URL: https://issues.apache.org/jira/browse/GROOVY-8051
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler, Static compilation, Static Type Checker
>Affects Versions: 2.4.7, 2.4.8
>Reporter: Daniil Ovchinnikov
>
> {code}
> @CompileStatic // works without this @CompileStatic
> class Outer {
>   def foo = 1
>   Inner createInner() { new Inner() }
>   class Inner {
> Closure createClosure() {
>   return { foo }
> }
>   }
> }
> @CompileStatic
> class Main {
>   static void main(String[] args) {
> def i = new Outer().createInner()
> def cl = i.createClosure()
> println cl()
>   }
> }
> {code}
> Fail in runtime with:
> {noformat}
> Exception in thread "main" 
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
> Cannot cast object 'Outer$Inner@23e028a9' with class 'Outer$Inner' to class 
> 'Outer'
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
>   at 
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
>   at Outer$Inner$_createClosure_closure1.doCall(innerclassestest.groovy)
>   at Outer$Inner$_createClosure_closure1.call(innerclassestest.groovy)
>   at Main.main(innerclassestest.groovy:23)
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


[jira] [Commented] (GROOVY-8051) Reference outer class property within inner class closure

2017-01-13 Thread Daniil Ovchinnikov (JIRA)

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

Daniil Ovchinnikov commented on GROOVY-8051:


Needs to be consistent

> Reference outer class property within inner class closure
> -
>
> Key: GROOVY-8051
> URL: https://issues.apache.org/jira/browse/GROOVY-8051
> Project: Groovy
>  Issue Type: Bug
>  Components: Compiler, Static compilation, Static Type Checker
>Affects Versions: 2.4.7
>Reporter: Daniil Ovchinnikov
>
> {code}
> @CompileStatic // works without this @CompileStatic
> class Outer {
>   def foo = 1
>   Inner createInner() { new Inner() }
>   class Inner {
> Closure createClosure() {
>   return { foo }
> }
>   }
> }
> @CompileStatic
> class Main {
>   static void main(String[] args) {
> def i = new Outer().createInner()
> def cl = i.createClosure()
> println cl()
>   }
> }
> {code}
> Fail in runtime with:
> {noformat}
> Exception in thread "main" 
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
> Cannot cast object 'Outer$Inner@23e028a9' with class 'Outer$Inner' to class 
> 'Outer'
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
>   at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
>   at 
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
>   at Outer$Inner$_createClosure_closure1.doCall(innerclassestest.groovy)
>   at Outer$Inner$_createClosure_closure1.call(innerclassestest.groovy)
>   at Main.main(innerclassestest.groovy:23)
> {noformat}



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