You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2016/02/10 00:02:18 UTC

[jira] [Commented] (GROOVY-7312) Compiler generates invalid inner class constructor

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

ASF GitHub Bot commented on GROOVY-7312:
----------------------------------------

GitHub user shils opened a pull request:

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

    GROOVY-7312 Add ACC_STATIC flag to inner classes of interfaces

    

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

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

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

    https://github.com/apache/groovy/pull/257.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 #257
    
----
commit 0012b17aa72e7f4ee6acaef93ea59d74c9559fc1
Author: Shil Sinha <sh...@gmail.com>
Date:   2016-02-09T23:00:16Z

    GROOVY-7312 Add ACC_STATIC flag to inner classes of interfaces

----


> Compiler generates invalid inner class constructor
> --------------------------------------------------
>
>                 Key: GROOVY-7312
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7312
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator, Compiler
>    Affects Versions: 2.4.0
>            Reporter: Adam Lewandowski
>            Priority: Minor
>
> replacement description:
> {code:title=Intf.groovy|borderStyle=solid}
> interface Intf {
>   def foo = { "bar" }
> }
> {code}
> Will create an inner class that lacks the static modifier for the inner class table. Compare with
> {code:title=JavaInterface.java}
> public interface JavaInterface {
>   class NestedInInterface {}
> }
> {code}for reference
> Original description:
> The JLS specifies that an implicitly-declared constructor of a non-private inner class "implicitly declares one formal parameter representing the immediately enclosing instance of the class" ([Section 8.8.9|http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.9], see also [8.8.1|http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.8.1]). 
> {code:title=Intf.groovy|borderStyle=solid}
> interface Intf {
>   def foo = { "bar" }
> }
> {code}
> The above code creates an inner class (Intf$1, not exactly sure what it's for) with a default constructor that has no parameters:
> {noformat}
> $ javap -p -classpath classes 'Intf$1'
> Compiled from "Intf.groovy"
> class Intf$1 implements groovy.lang.GroovyObject {
>   ...
>   public Intf$1();
>   ...
> }
> {noformat}
> While not a major issue, this non-conformance can break interoperability with anything that expects to work with Java classes. This particular example came up while trying to use a similarly-declared Groovy class from a Scala class, where the Scala compiler was unable to parse the generated inner class.
> For reference, here is an example Java Inner class and it's compiled representation. Note the constructor parameter on the inner class.
> {code:title=JavaObj.java|borderStyle=solid}
> public class JavaObj {
>   public class Inner {}
> }
> {code}
> {noformat}
> $ javap -p -classpath classes 'JavaObj$Inner'
> public class JavaObj$Inner {
>   final JavaObj this$0;
>   public JavaObj$Inner(JavaObj);
> }
> {noformat}



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