Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inner types in prototype style #41

Closed
ikasiuk opened this issue Feb 7, 2012 · 4 comments
Closed

Inner types in prototype style #41

ikasiuk opened this issue Feb 7, 2012 · 4 comments
Assignees

Comments

@ikasiuk
Copy link
Member

ikasiuk commented Feb 7, 2012

Inner types are currently only partly functional in prototype style. For instance, this doesn't work:

class Outer() {
    class Inner() {
        shared String s = "hello";
    }
    shared String test() { return Inner().s; }
}

In the generated JS code test can't access Outer.Inner() properly because it is defined inside Outer and is not exported. That could be fixed of course. But perhaps the real problem is that we mix prototype style and capture style here: while methods are defined separately and added to the prototype, inner types are defined inside the body of the outer type, creating a closure. It seems that this mixing of concepts is not completely trouble-free.

It would be more consistent, and probably work out better in the long term, to define inner types in the same way as other class members in prototype style. It would also definitely be more efficient because currently inner types are completely initialized every time an instance of the outer class is created.
Implementing this is definitely not uncomplicated either though.

@chochos
Copy link
Member

chochos commented Feb 7, 2012

Right because you must differ the generation of the inner class until after the constructor is done... interesting problem.

@ikasiuk
Copy link
Member Author

ikasiuk commented Feb 8, 2012

After playing around with some JavaScript code I think it should be possible to move the inner types out of the class body. I'll need to refactor the generated code a bit first.

@ikasiuk
Copy link
Member Author

ikasiuk commented Feb 12, 2012

Inner types in prototype style are now added to the prototype instead of being defined in the class body. All the tests still pass, and correct code is generated for the example given above. As a nice side effect the prototype style code is now more readable because the members are grouped properly.

But there are probably some cases that still don't work, for both prototype style and capture style, in particular if inner and outer types have identical names.

ikasiuk added a commit that referenced this issue Feb 13, 2012
@ikasiuk ikasiuk closed this as completed Feb 13, 2012
@ikasiuk
Copy link
Member Author

ikasiuk commented Feb 13, 2012

Ok, this seems to work pretty well now. The problems with identical names of inner and outer types are not directly related to this, so I'll open a separate issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants