dao
dao copied to clipboard
Bug with variadic parameters
(dao) load net.http
= none
(dao) routine f(...: tuple<enum,int|string|list<string>> as args){
..... http.initRequest('GET', 'some', args, ...)
..... }
[[ERROR]] in file "interactive codes":
At line 1 : Invalid function definition --- " f() ";
At line 2 : Invalid virtual machine instruction --- " MCALL:34,17412,39 ";
In code snippet:
6 : MOVE_PP : 32 , 0 , 38 ; 2; args
>> 7 : MCALL : 34 , 17412 , 39 ; 2; http. initRe...('GET', '...'...
8 : RETURN : 39 , 1 , 0 ; 2; http. initRequest('GET',...
** Invalid parameter type --- " '...:tuple<enum,int|string|list<string>>' for 'tuple<enum,int|string|list<string>>' ";
Assuming : routine initRequest(method:string,url:string,...:tuple<enum,int|string|list<string>>)=>string;
Reference : file "http";
Fixed.
(dao) load net.http
= none
(dao) routine request(method: string, url: string, ...: tuple<enum,int|string|list<string>> as fields){
..... http.initRequest('GET', url, fields, ...)
..... }
[[ERROR]] in file "interactive codes":
At line 1 : Invalid function definition --- " request() ";
At line 2 : Invalid virtual machine instruction --- " MCALL:34,17412,39 ";
In code snippet:
6 : MOVE_PP : 32 , 0 , 38 ; 2; fields
>> 7 : MCALL : 34 , 17412 , 39 ; 2; http. initRe...('GET', u...
8 : RETURN : 39 , 1 , 0 ; 2; http. initRequest('GET',...
** Invalid parameter type --- " 'string' for 'tuple<enum,int|string|list<string>>' ";
Assuming : routine initRequest(method:string,url:string,...:tuple<enum,int|string|list<string>>)=>string;
Reference : file "http";
fields also includes the method and url parameters, so they are also expanded there, and their types are not correct for the variadic parameter of http.initRequest().
I would expect fields to capture only the last, variadic part of routine parameters, as there is arguably no use in capturing other, fixed arguments.
The choice was made to simplify the implementation, otherwise, we will need to add a dedicated virtual instruction or modify the DVM_TUPLE instruction for this. But if this is too confusing, I will change it.
I could never thought it worked that way. Either the semantics or the syntax should better be changed.
The choice was made to simplify the implementation, otherwise, we will need to add a dedicated virtual instruction or modify the
DVM_TUPLEinstruction for this. But if this is too confusing, I will change it.
I came across this and have to admit it's really confusing. Any plans to change it?