Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

implement singleton constructors #2176

Closed
CeylonMigrationBot opened this issue Jun 1, 2015 · 21 comments
Closed

implement singleton constructors #2176

CeylonMigrationBot opened this issue Jun 1, 2015 · 21 comments

Comments

@CeylonMigrationBot
Copy link

[@gavinking] Whenever you guys feel like it, it should be easy to implement support for #4235.

[Migrated from ceylon/ceylon-compiler#2176]
[Closed at 2015-08-19 08:54:31]

@CeylonMigrationBot
Copy link
Author

[@tombentley] Pushed some initial support for this to the spec1129 branch. Still to do:

  • support for singletons constructors for member classes of interfaces and local classes
  • model loading
  • delegation (if singleton ctors support delegation...?)
  • use of singleton constructors as a annotation target (including interop)
  • investigate/fix of interop enum switching

But there should be enough to play with.

@CeylonMigrationBot
Copy link
Author

[@gavinking] Awesome!

Singleton constructors should eventually support delegation to partial constructors. But we don't need to support that until we have time to implement it. The typechecker doesn't yet support it. So let's get the rest working first!

@CeylonMigrationBot
Copy link
Author

[@gavinking]
@tombentley this code:

class MyPoint {
    shared Float x;
    shared Float y;
    shared new origin {
        x = 0.0;
        y = 0.0;
    }
    string => "(``x``, ``y``)";
}

void runWithPoint() {
    print(MyPoint.origin);
}

Gives me:

GetOrigin() has private access in calendar.MyPoint

@CeylonMigrationBot
Copy link
Author

[@tombentley] Should be fixed now.

@CeylonMigrationBot
Copy link
Author

[@gavinking] Cool, thanks, let's see.

@CeylonMigrationBot
Copy link
Author

[@tombentley] I think I'm done on this for now (until such time as we actually decide to merge this stuff). At which point:

  • Fix interop enum support
  • Need metamodel support for these things.
  • Need more tests, for example with singletons listed in of clauses

@CeylonMigrationBot
Copy link
Author

[@gavinking]
@tombentley I'm in the IDE, attempting to compile this:

class Point {
    shared Float x;
    shared Float y;
    shared new origin {
        x = 0.0;
        y = 0.0;
    }

It passes the typechecker, but the backend gives me:

The Ceylon Java backend compilation failed
  with a throwable : com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.redhat.ceylon.compiler.java.metadata.Enumerated not found

@CeylonMigrationBot
Copy link
Author

[@gavinking] On the command line I get:

com.redhat.ceylon.compiler.CompilerBugException: Bug
    at com.redhat.ceylon.compiler.CeylonCompileTool.handleExitCode(CeylonCompileTool.java:522)
    at com.redhat.ceylon.compiler.CeylonCompileTool.run(CeylonCompileTool.java:504)
    at com.redhat.ceylon.common.tools.CeylonTool.run(CeylonTool.java:390)
    at com.redhat.ceylon.common.tools.CeylonTool.execute(CeylonTool.java:327)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.redhat.ceylon.launcher.Launcher.runInJava7Checked(Launcher.java:114)
    at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:41)
    at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.redhat.ceylon.launcher.Bootstrap.run(Bootstrap.java:55)
    at com.redhat.ceylon.launcher.Bootstrap.main(Bootstrap.java:32)
Caused by: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.redhat.ceylon.compiler.java.metadata.Enumerated not found

@CeylonMigrationBot
Copy link
Author

[@tombentley] You pulled the spec_Whatever_ branch of ceylon.language and rebuilt everything?

@CeylonMigrationBot
Copy link
Author

[@gavinking] aaah you have a branch of c.l now too.

@CeylonMigrationBot
Copy link
Author

[@tombentley] I told you that, though admittedly not here on the issue.

@CeylonMigrationBot
Copy link
Author

[@gavinking]
@tombentley this class:

class Bool {
    shared new true {}
    shared new false {}
}

Results in:

Cannot find symbol
  symbol:   variable true
  location: class calendar.Bool

Renaming to truex and falsex solves the problem. Some name-mangling issue, I imagine.

@CeylonMigrationBot
Copy link
Author

[@gavinking] Also:

import calendar {
    Bool {
        t=true_,
        f=false_
    }
}

Bool bt = t;

Results in:

compiler bug: calendar::Bool.true_ was unexpectedly a member at com.redhat.ceylon.compiler.java.codegen.ExpressionTransformer.addThisOrObjectQualifierIfRequired(ExpressionTransformer.java:4693)

@CeylonMigrationBot
Copy link
Author

[@gavinking] @tombentley finally, static refs to singleton constructors of member classes, for example, Outer.Inner.instance, don't seem to be working. (They weren't working in the typechecker either, FTR, until just then.)

@CeylonMigrationBot
Copy link
Author

[@sgalles] I'm not sure, does this belong to this issue ?
this code

import foo{
    Foo {bar}
}

class Foo{
    shared new bar{}
}

shared void run(){
    Foo f = bar;
    print(f);
}
  • compiled with the java backend : NPE
  • executed with the JS backend outputs <null>

Or should I open two issues ?

@CeylonMigrationBot
Copy link
Author

[@FroMage] Yes please. This issue is about something which is merged no ? Why is it 1.3 then?

@CeylonMigrationBot
Copy link
Author

@CeylonMigrationBot
Copy link
Author

[@FroMage] @tombentley have the last comments reported by @gavinking been fixed already or not? If yes then why is this issue still open?

@CeylonMigrationBot
Copy link
Author

[@tombentley] I don't think they have, yet. I'll do those next.

@CeylonMigrationBot
Copy link
Author

[@FroMage] Oh, OK thanks.

@CeylonMigrationBot
Copy link
Author

[@tombentley] This is now done.

quintesse pushed a commit that referenced this issue Nov 14, 2015
… ctors in value expressions, which means "switch" just works.
quintesse pushed a commit that referenced this issue Nov 14, 2015
quintesse pushed a commit that referenced this issue Nov 14, 2015
…local classes, which turned out quite messy because I need to eagerly instantiate each instance after the decl of the local class. We didn't seem to have a way of doing that before, so I renamed ClassDefinitionBuilder.also() to before() (since add prepended arbitrary trees before the class) and added an after().
quintesse pushed a commit that referenced this issue Nov 14, 2015
…annotations to singleton constructors (and fix a omission to do with constructors annotated incorrectly).
quintesse pushed a commit that referenced this issue Nov 14, 2015
…applying annotations to singleton constructors,
quintesse pushed a commit that referenced this issue Nov 14, 2015
This is not a whole true, however, because the model loader does
still look at them, at least in order to support importing constructors
as in #2176. But we don't want the model loader to see them as methods.

Part of #5635
quintesse pushed a commit that referenced this issue Nov 14, 2015
We need to find the getters for value constructor in order to
support importing constructors (as in #2176)
but otherwise ignore them.

Part of #5635
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants