Hi there,
Just found that following construct: mapping m = ([ "key": "value" ]); array a = ({ m }); foreach (a; ; int v) // Note the type of v write("%O", v); ...does work (7.6.6) - it prints mapping, while typeof(v) is int (_typeof(v) is mapping, however).
Actually, it doesn't matter which type is used to declare v - it will work anyway - both for indexes and values: foreach (anyvalue; int k; int v) // This will always work, regardless write("%O=%O\n", k, v); // of type of anyvalue and it's elements Seems to be a bug or? Regards, /Al
no, it's an issue of compile time vs runtime typechecking. types are checked at compile time.
compare with:
array(mapping) b = ({ m }); foreach (b; ; int v)
write("%O", v);
Compiler Error: 1:Type mismatch for value in foreach(). Compiler Error: 1:Expected: mapping Compiler Error: 1:Got : int Compiler Error: 1:Variable type mismatch in foreach(). Compiler Error: 1:Expected: mapping Compiler Error: 1:Got : int
at runtime mixed can always be assigned to any other type.
i think the option for strict type checking may cause pike to complain because it won't allow to assign mixed to anything but mixed.
greetings, martin.
If you add #pragma strict_types to the file and still get that behaviour, it would be a bug. If you don't (add the line), you can only be sure your program is less future safe than it would be with a correct type there.
/ Johan Sundström (Achtung Liebe!)
Previous text:
2004-06-06 19:37: Subject: Data types in foreach
Hi there,
Just found that following construct:
mapping m = ([ "key": "value" ]); array a = ({ m });
foreach (a; ; int v) // Note the type of v write("%O", v); ...does work (7.6.6) - it prints mapping, while typeof(v) is int (_typeof(v) is mapping, however).
Actually, it doesn't matter which type is used to declare v - it will work anyway - both for indexes and values:
foreach (anyvalue; int k; int v) // This will always work, regardless write("%O=%O\n", k, v); // of type of anyvalue and it's elements
Seems to be a bug or?
Regards, /Al
/ Brevbäraren
pike-devel@lists.lysator.liu.se