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).

Reply via email to