dao icon indicating copy to clipboard operation
dao copied to clipboard

Bug with variadic parameters

Open Night-walker opened this issue 10 years ago • 7 comments

(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";

Night-walker avatar Jul 13 '15 13:07 Night-walker

Fixed.

daokoder avatar Jul 13 '15 14:07 daokoder

(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";

Night-walker avatar Jul 13 '15 15:07 Night-walker

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().

daokoder avatar Jul 13 '15 15:07 daokoder

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.

Night-walker avatar Jul 13 '15 16:07 Night-walker

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.

daokoder avatar Jul 13 '15 17:07 daokoder

I could never thought it worked that way. Either the semantics or the syntax should better be changed.

Night-walker avatar Jul 13 '15 18:07 Night-walker

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 came across this and have to admit it's really confusing. Any plans to change it?

dumblob avatar Apr 13 '19 10:04 dumblob