ceylon/ceylon-js

spread w/variadic doesn't work

Closed this issue · 5 comments

These are wrong:

shared void run() {
    // with default
    [Integer+] fa(Integer a, Integer b=99, Integer* rest) => [a, b, *rest];

    print(fa(*[1]));        // [1, 99, ]
    print(fa(*[1,2]));      // [1, 2, ]
    print(fa(*[1,2,3]));    // error
    print(fa(*[1,2,3,4]));  // error

    print(fa(1));           // [1, 99, ]
    print(fa(1, *[]));      // error
    print(fa(1, *[2]));     // [1, 2, ]
    print(fa(1, *[2,3]));   // error
    print(fa(1, *[2,3,4])); // error

    // no default
    [Integer+] fb(Integer a, Integer b, Integer* rest) => [a, b, *rest];

    print(fb(*[1,2]));      // [1, 2, ]
    print(fb(*[1,2,3]));    // error
    print(fb(*[1,2,3,4]));  // error

    print(fb(1, *[2]));     // [1, 2, ]
    print(fb(1, *[2,3]));   // error
    print(fb(1, *[2,3,4])); // error
}

These work:

shared void run() {
    // no variadic default
    [Integer+] fc(Integer a, Integer b=99) => [a, b];

    print(fc(*[1]));
    print(fc(*[1,2]));
    print(fc(1, *[2]));

    // no variadic no default
    [Integer+] fd(Integer a, Integer b) => [a, b];

    print(fd(*[1,2]));
    print(fd(1, *[2]));
}

Many of these fail too:

shared void run() {
    // with default
    [Integer+] fa(Integer a, Integer b=99, Integer* rest) => [a, b, *rest];

    print(fa(1));
    //print(fa(1, *[]));
    print(fa(1, 2));
    print(fa(1, 2, *[]));
    print(fa(1, 2, *[3]));
    print(fa(1, 2, 3));
    print(fa(1, 2, 3, *[]));
    print(fa(1, 2, 3, *[4]));
    print(fa(1, 2, 3, *[4, *[]]));

    // without default
    [Integer+] fb(Integer a, Integer b, Integer* rest) => [a, b, *rest];

    print(fb(1, 2));
    print(fb(1, 2, *[]));
    print(fb(1, 2, *[3]));
    print(fb(1, 2, 3));
    print(fb(1, 2, 3, *[]));
    print(fb(1, 2, 3, *[4]));

    // with default, without variadic
    [Integer+] fc(Integer a, Integer b=98, Integer c=99) => [a, b, c];

    print(fc(1));
    print(fc(1, 2));
    print(fc(1, 2, 3));

    // with only variadic
    [Integer*] fd(Integer* rest) => rest;

    print(fd());
    print(fd(*[]));
    print(fd(1));
    print(fd(1, *[]));
    print(fd(1, 2));
    print(fd(1, 2, *[]));

    print(type(fd(1)));         // ceylon.language::Array<ceylon.language::Integer> !!!
    print(type(fd(1, *[])));    // error
    print(type(fd(1, 2)));      // ceylon.language::Array<ceylon.language::Integer> !!!
    print(type(fd(1, 2, *[]))); // error

    // with no params
    [Integer*] fe() => [];
    print(fe());
    print(fe(*[]));             // GenerateJsVisitor caused an exception visiting
}

ok nothing fails now. They do print a bit different from JVM though.

cool, looks good!

So @chochos if this is fixed, why not close it?

I was waiting for @jvasileff to do the honor, but some things print different in JVM; I'm not sure it's wrong, but it's different from the JVM. For example JVM prints [1,2, *[3,4]] and JS just prints [1,2,3,4] but I think that should be irrelevant.

Anyway if that is a bug then yeah it should be filed separately.