eclipse-archived / ceylon

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

Backend error when using static member of generic class #6991

Open kingjon3377 opened 7 years ago

kingjon3377 commented 7 years ago

This code

class Mwe<Type> {
    static String temp = "xyzzy";
    static void mwe() {
        process.writeLine(temp);
    }
    shared new() {}
}

fails to compile in the command-line distribution with the following output:

source/mwe/inout.ceylon:1: warning: declaration is never used: type parameter 'Type' has no local references
class Mwe<Type> {
          ^
source/mwe/inout.ceylon:3: warning: declaration is never used: function 'mwe' has no local references
    static void mwe() {
                ^
source/mwe/inout.ceylon:4: error: Ceylon backend error: method getTemp$priv$ in class Mwe<Type#1> cannot be applied to given types;
        process.writeLine(temp);
                          ^
  required: TypeDescriptor
  found: no arguments
  reason: cannot infer type-variable(s) Type#2
    (actual and formal argument lists differ in length)
  where Type#1,Type#2 are type-variables:
    Type#1 extends Object declared in class Mwe
    Type#2 extends Object declared in method <Type#2>getTemp$priv$(TypeDescriptor)
Note: Created module mwe/0.0.1
ceylon compile: There was 1 error

ceylon --version reports ceylon version 1.3.2 754a09a (Smile Tolerantly), and this is on Mac OS X Sierra, with Ceylon installed via Homebrew. The code compiles fine in the IntelliJ IDE.

jvasileff commented 7 years ago

This is somewhat related to https://github.com/ceylon/ceylon/issues/6839 and https://github.com/ceylon/ceylon/issues/6870. How static values of generic classes are supposed to work isn't yet clear.

Note that if we make temp shared, this also fails:

class Mwe<Type> {
    shared static String temp = "xyzzy";
    shared new() {
        process.writeLine(temp);
    }
}
gavinking commented 7 years ago

This is somewhat related to https://github.com/ceylon/ceylon/issues/6839 and https://github.com/ceylon/ceylon/issues/6870. How static values of generic classes are supposed to work isn't yet clear.

Doesn't really look related to me. It seems pretty clear that this code should be allowed, and what it should do. I don't see what's unclear in this case.

jvasileff commented 7 years ago

Of course it should be allowed. The question is whether or not static value getters should have parameters for types.