On 10/29/2013 09:15 AM, Maxim Fomin wrote: > On Tuesday, 29 October 2013 at 12:43:17 UTC, bearophile wrote: >> This code is accepted by the D compiler: >> >> >> enum Foo { A, B, C } >> void main() { >> bool[5] bools; >> auto b = bools[2] != Foo.C; >> bools[2] = Foo.A; >> } >> >> >> Who is that likes such kind of code? What are the advantages of >> accepting such kind of code? I can see the disadvantages and risks. >> >> Bye, >> bearophile > > Probably may be related to even worse issue: > > import std.stdio; > > void foo(bool b) { writeln("bool"); } > void foo(long l) { writeln("long"); } > > void main() > { > foo(0); // bool > foo(1); // bool > foo(2); // long > int i = true; > foo(i); // long > } > > If reasons for accepting yours and this example are the same, then this > is by design (to be more precise, the part which is related to bool > types being essentially kind of integer types + VRP + overloading rules).
There was a long discussion about that. Walter was happy that bool was a integer type. Many of us had objections:
http://forum.dlang.org/thread/klc5r7$3c4$1...@digitalmars.com Ali