[Issue 8823] static if (A || B) != static if (A) else if (B) in some cases

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 15 07:44:41 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8823



--- Comment #1 from Jameson <beatgammit at gmail.com> 2012-10-15 07:44:35 PDT ---
It also does not work reliably if I change them to regular if blocks:

    import std.stdio;

    class A {
        string s;
    }

    void main() {
        A a = new A;
        foreach (t; __traits(allMembers, A)) {
            static if (is(typeof(__traits(getMember, A, t)) == function)) {
                continue;
            }
            static if (is(typeof(__traits(getMember, a, t)) == function)) {
                continue;
            }
            static if (t == "Monitor") {
                continue;
            }

            __traits(getMember, a, t) = "hello";
        }
    }


Tt works if I nest under a common else:

    import std.stdio;

    class A {
        string s;
    }

    void main() {
        A a = new A;
        foreach (t; __traits(allMembers, A)) {
            static if (is(typeof(__traits(getMember, A, t)) == function)) {
                continue;
            } else {
                static if (is(typeof(__traits(getMember, a, t)) == function)) {
                    continue;
                } else {
                    static if (t == "Monitor") {
                        continue;
                    } else {
                        __traits(getMember, a, t) = "hello";
                    }
                }
            }
        }
    }

It seems the workaround is nesting.

It looks as if 'else if' in general doesn't work as expected. It serves as a
regular 'if', but without the knowledge from the preceding 'if' conditionals.
In my implementation, I have more than 5 conditionals (all different bodies),
but each assumes that the previous conditionals evaluated to false.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list