hi,
when doing search i get the following strange error. can anyone explain what this is about?
search(({ 3,4,5,1,2,3 }), "a");
Compiler Error: 1:Bad argument 2 to search. Compiler Error: 1:Expected: function(string, string | int, void | int : int) | function(array((0=mixed)), 0, void | int : int) | function(mapping((1=mixed):(2=mixed)), 2, void | 1 : 1) | !(function(!array, mixed, void | int : mixed) | function(!mapping, mixed, void | int : mixed)) & function(mapping | array, mixed, void | int : zero) Compiler Error: 1:Got : function(array(int(3..3) | int(2..2) | int(1..1) | int(3..5)), string : void | mixed)
greetings, martin.
The type checker thinks that you have made an error when you are looking for a string in array(int).
On Sun, 2 Jan 2005 19:35:08 +0100 (CET), Martin Nilsson (DivX Networks) @ Pike (-) developers forum 10353@lyskom.lysator.liu.se wrote: | The type checker thinks that you have made an error when you are looking | for a string in array(int).
search(({ 23, 2 }), 2);
(4) Result: 1
search(({ 23, 2 }), 3);
Compiler Error: 1:Bad argument 2 to search. Compiler Error: 1:Expected: function(string, string | int, void | int : int) | function(array((0=mixed)), 0, void | int : int) | function(mapping((1=mixed):(2=mixed)), 2, void | 1 : 1) | !(function(!array, mixed, void | int : mixed) | function(!mapping, mixed, void | int : mixed)) & function(mapping | array, mixed, void | int : zero) Compiler Error: 1:Got : function(array(int(2..2) | int(23..23)), int(3..3) : void | mixed)
it fails here too:
search(({ "3","4","5","1","2","3",7,3 }), 9);
Compiler Error: 1:Bad argument 2 to search. Compiler Error: 1:Expected: function(string, string | int, void | int : int) | function(array((0=mixed)), 0, void | int : int) | function(mapping((1=mixed):(2=mixed)), 2, void | 1 : 1) | !(function(!array, mixed, void | int : mixed) | function(!mapping, mixed, void | int : mixed)) & function(mapping | array, mixed, void | int : zero) Compiler Error: 1:Got : function(array(int(3..3) | int(7..7) | string), int(9..9) : void | mixed)
the problem does go away if i put the array into a variable, (but i am trying to think of a case where i would not want to do that ;-)
Let us now if you do find one. We can always have search be optimized to 0 instead of throwing the error. But only if someone can come up with a non-silly example of why.
In the last episode (Jan 02), Martin Nilsson (DivX Networks) @ Pike (-) developers forum said:
Let us now if you do find one. We can always have search be optimized to 0 instead of throwing the error. But only if someone can come up with a non-silly example of why.
Auto-generated pike code?
This bug existed for age. It happens only in hilfe IIRC.
/ David
On Sun, 2 Jan 2005 19:44:58 +0100, Martin Baehr mbaehr@email.archlab.tuwien.ac.at wrote:
it fails here too:
search(({ "3","4","5","1","2","3",7,3 }), 9);
Compiler Error: 1:Bad argument 2 to search. Compiler Error: 1:Expected: function(string, string | int, void | int : int) | function(array((0=mixed)), 0, void | int : int) | function(mapping((1=mixed):(2=mixed)), 2, void | 1 : 1) | !(function(!array, mixed, void | int : mixed) | function(!mapping, mixed, void | int : mixed)) & function(mapping | array, mixed, void | int : zero) Compiler Error: 1:Got : function(array(int(3..3) | int(7..7) | string), int(9..9) : void | mixed)
the problem does go away if i put the array into a variable, (but i am trying to think of a case where i would not want to do that ;-)
Which I still think is wrong, since search() doesn't complain. Same issue with 17=="s" and 17!="s".
A warning would be much more suitable.
I think so too. If there was infrastructure in place to specify both warning and error level type checking, it would be.
That shouldn't be too hard to implement. Just a tWarn flag somewhere, and you get a "Type warning" or so.
But you need two types. Just because some type mismatches should produce warnings doesn't mean that all real type errors should be reduced to warnings.
Maybe tWarn(non-warn-type,warn-type)? Works as or, but gives a warning if the second type is matched.
tWarn(tOrN(tFunction(tInt tInt,tInt01), tFunction(tString tString,tInt01), ...), tFunction(tMix tMix,tInt01))
or so.
pike-devel@lists.lysator.liu.se