[Bro-Dev] #957: Argument names must match when passing a function by value

Bro Tracker bro at tracker.bro.org
Thu Mar 7 07:51:25 PST 2013


#957: Argument names must match when passing a function by value
------------------------+---------------------
 Reporter:  srunnels    |       Type:  Problem
   Status:  new         |   Priority:  Low
Milestone:  Bro2.2      |  Component:  Bro
  Version:  git/master  |   Keywords:
------------------------+---------------------
 It appears you have to match the name of arguments passed to functions in
 order to pass those functions by value.
 If the arguments in the prototypes don't match a type clash occurs.


 Example script:

 function double_string(s: string): string
     {
     return string_cat(s, " ", s);
     }

 function triple_string(str: string): string
     {
     return string_cat(str, " ", str, " ", str);
     }

 type sample_function: record {
     s: string;
     f: function(str: string): string;
 };

 event bro_init()
     {
     local test_sf: sample_function;
     test_sf$s = "Brogrammers, like bowties, are cool.";

     # Works as expected
     test_sf$f = triple_string;
     print test_sf$f(test_sf$s);

     # Fails with: error in <command line>, line 22: type clash in
 assignment (test_sf$f = double_string)
     test_sf$f = double_string;
     print test_sf$f(test_sf$s);

     # Works as expected
     test_sf$f = function(str: string): string
         { return to_upper(str); };
     print test_sf$f(test_sf$s);

     # Fails with: error in <command line>, lines 38-39: type clash in
 assignment (test_sf$f = anonymous-function{ return (to_upper(s))})
     test_sf$f = function(s: string): string
         { return to_upper(s); };
     print test_sf$f(test_sf$s);

     }

-- 
Ticket URL: <http://tracker.bro.org/bro/ticket/957>
Bro Tracker <http://tracker.bro.org/bro>
Bro Issue Tracker



More information about the bro-dev mailing list