Calling function with wrong type of arg should generate run-time error!
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=7820
Reported by Karl Gustav Sterneberg kg@roxen.com
Today I accidentally called a function taking a multiset with an array as argument. Got some strange behaviour. When I found out my mistake I did the following experiment:
int main(int argc, array(string) argv)
{
object ref = Bar();
ref->my_function((<"Adam", "Bertil">));
ref->my_function(({"Adam", "Bertil"}));
return 0;
}
class Bar {
void my_function(multiset my_set) {
werror("multisetp(my_set): %O\n", multisetp(my_set));
werror("arrayp(my_set): %O\n", arrayp(my_set));
foreach(my_set; mixed entry;) {
werror("entry: %O\n", entry);
}
}
}
pike arg-match.pike multisetp(my_set): 1 arrayp(my_set): 0 entry: "Adam" entry: "Bertil" multisetp(my_set): 0 arrayp(my_set): 1 entry: 0 entry: 1
The problem as I see it is that this should blow up at runtime! As now it can give your system strange behaviour.
If I change "object ref = Bar();" to "Bar ref = Bar();" the compiler will complain:
>pike arg-match.pike
arg-match.pike:5:Bad argument 1 to my_function.
arg-match.pike:5:Expected: multiset.
arg-match.pike:5:Got : array(string(65..116)).
Pike: Failed to compile script.
By not using a properly typed object reference, it is understandable that the compiler might not be able to see the problem. Then however you should get a run-time error!