Class member/initialization shorthand conflicts with ellipsis

Chris Angelico <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <CAPTjJmqQRxgp=JSAO9G+JnyhyvVn6RmypCnTBK7cbTkthYvtkg@mail.gmail.com>
The shorthand for constructing a class with members and initialization
is really handy:

class Person(string name) {...}
object fred=Person("Fred");

But it doesn't seem to work with the "mixed ... moreargs" notation.

class cls(mixed ... args) {void create() {write("args: %O\n",args);}}
int main()
{
    //mixed cls=cls;
    cls(); cls(1);
}

extra_args.pike:5:Too few arguments to cls (got 0).
extra_args.pike:5:Expected: array.
extra_args.pike:5:Function type:
extra_args.pike:5:Got     : function(array : object(is
/home/rosuav/extra_args()->cls)).
extra_args.pike:5:Bad argument 1 to cls.
extra_args.pike:5:Expected: array.
extra_args.pike:5:Got     : int(1..1).
Pike: Failed to compile script.

It's expecting a prepackaged array. Uncommenting "mixed cls=cls;" (and
thus defeating the compiler's detection of expected parameters) allows
it to run; the result is then:

args: 0
Wrong type in assignment, expected array, got int.
extra_args.pike:1: /main()->cls()->create(1)
extra_args.pike:5: /main()->main()

So it's still expecting the array, rather than packaging up all remaining args.

Tested on Pike 8.1 and 7.8. Is this something that could potentially
be improved on, or is it not worth the hassle?

ChrisA
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.