[Issue 10926] Wrong expression printed when ternary operator used as lvalue

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 12 10:29:11 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=10926



--- Comment #5 from bearophile_hugs at eml.cc 2013-11-12 10:29:09 PST ---
(In reply to comment #4)

> Would this make any sense?
> 
> (cast(const(int)[])c) ~= 20;


You are probably right, but it's quite surprising:


void main() {
    const(int)[] a, b;
    int[] c, d;
    (true ? a : b) ~= 10; // OK
    (true ? c : d) ~= 20; // OK
    (true ? a : c) ~= 30; // Error: cast(const(int)[])c is not an lvalue
    if (true)
        a ~= 40; // OK
    else
        c ~= 40; // OK
}


So if both are fully mutable, or both have const items then you can append to
them, but if one of them is mutable and the other has const items, then it
can't append and you have to use a regular if statement.

Thank you for your answer, I'll keep this issue closed.

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


More information about the Digitalmars-d-bugs mailing list