daokoder / dao

Dao Programming Language
http://daoscript.org
Other
198 stars 19 forks source link

Bug: type matching issue of Error types #512

Open dumblob opened 9 years ago

dumblob commented 9 years ago
0$ dao -e 'const e = Error::define("Error", "description ..."); std.error(e)'
[[ERROR]] in file "command line codes":
  At line 0 : Invalid function definition --- " __main__() ";
  At line 1 : Invalid virtual machine instruction --- " MCALL:1,2,4 ";
In code snippet:
      3 :  GETCG       :     0 ,    25 ,     3 ;     1;   e
>>    4 :  MCALL       :     1 ,     2 ,     4 ;     1;   std. error(e)
      5 :  RETURN      :     4 ,     1 ,     0 ;     1;   )
  ** Invalid number of parameter --- " too few parameters ";
     Assuming  : routine error(errorType:Error,info:string,data=any)=>none;
     Reference : file "std";
  ** Invalid parameter type --- " 'const<Error>' for 'Error' ";
     Assuming  : routine error(errorObject:Error)=>none;
     Reference : file "std";
  ** Invalid parameter type --- " 'const<Error>' for 'string' ";
     Assuming  : routine error(info:string)=>none;
     Reference : file "std";
1$ dao -e 'e = Error::define("Error", "description ..."); std.error(e)'
[[ERROR]] in file "command line codes":
  At line 0 : Invalid function definition --- " __main__() ";
  At line 1 : Invalid virtual machine instruction --- " MCALL:7,2,10 ";
In code snippet:
      9 :  MOVE_PP     :     5 ,     0 ,     9 ;     1;   e
>>   10 :  MCALL       :     7 ,     2 ,    10 ;     1;   std. error(e)
     11 :  RETURN      :    10 ,     1 ,     0 ;     1;   )
  ** Invalid number of parameter --- " too few parameters ";
     Assuming  : routine error(errorType:Error,info:string,data=any)=>none;
     Reference : file "std";
  ** Invalid parameter type --- " 'Error' for 'Error' ";
     Assuming  : routine error(errorObject:Error)=>none;
     Reference : file "std";
  ** Invalid parameter type --- " 'Error' for 'string' ";
     Assuming  : routine error(info:string)=>none;
     Reference : file "std";
Night-walker commented 9 years ago

You're using the wrong overloaded routine. It's std.error(e, 'detailed description').

dumblob commented 9 years ago

Right, bad mistake of mine - I got confused with " 'Error' for 'Error' " (the message should distinguish between Error object type and Error type type).

By the way, It would make sense to change

routine error(errorType:Error, info:string, data=any) => none

to

routine error(errorType:Error, info:string='', data=any) => none