eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
395 stars 62 forks source link

Cannot reference constructor when using initializer params #7388

Open diredev opened 5 years ago

diredev commented 5 years ago

I am able to reference a named constructor by using `new MyClass.named` or the unnamed one with `new MyClass`. I then assumed that I could do the same for classes that use initializer parameters instead.

This will not compile however, the error message "Referenced declaration is not a constructor: NoCtor is a class" is displayed instead:

class NoCtor(String name) {}

class WithCtor {
    shared new(String name) {}
}

// This works as expected
value ctor = `new WithCtor`;

// TODO: This does not compile
value ctor2 = `new NoCtor`;

// NOTE: You can access the CallableConstructor using reflection
value ctorR = `class WithCtor`.constructorDeclarations().first;
value ctorR2 = `class NoCtor`.constructorDeclarations().first;

This applies to both Eclipse (Ceylon 1.3.3) and the Web IDE (see here).

gavinking commented 5 years ago

Right, this behavior is what is defined by the language specification. However, I agree that it does violate the expectation that one can change between default constructors and initializers without breaking code.