[Issue 4375] Require explicit braces when 'else' is ambiguous

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Aug 3 18:59:38 PDT 2011


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



--- Comment #17 from bearophile_hugs at eml.cc 2011-08-03 18:59:30 PDT ---
I've being hit by a "dangling else" bug in D, traslating this Python code:


def foo(sol):
    global best
    if is_solution(sol[-1]):
        if best or len(sol) < len(best):
            best = list(sol)
    else:
        for next in alternatives(sol[-1]):
            if next not in sol:
                foo(sol + [next])


to the wrong D code:


void foo(Pair[] sol) {
    if (isSolution(sol[$-1]))
        if (!best.length || sol.length < best.length)
            best = sol.dup;
    else
        foreach (next; alternatives(sol[$-1]))
            if (!canFind(sol, next))
                foo(sol ~ [next]);
}

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