that is bug?

kdevel kdevel at vogtner.de
Sat Apr 7 21:22:07 UTC 2018


On Saturday, 7 April 2018 at 19:44:35 UTC, Ali wrote:
> so it seems
> that since
>     b = (true ? stt="AA": stt )="BB";
> and
>     b = true ? stt="AA": stt ="BB";
>
> are equivalent
> that
>
> that the ternary operator return stt (after assigning it "AA") 
> then assign "BB" to it

Can the ternary conditional even be used to assign objects of the 
wrong type?

dcondo.d
---
import std.stdio;

class A {
    int a;
    this (int i)
    {
       a = i;
    }
}

class C {
    int c;
    this (int i)
    {
       c = i;
    }
}

void dump (A a, A b, C c, C d)
{
    a.writeln;
    b.writeln;
    c.writeln;
    d.writeln;
    a.a.writeln;
    b.a.writeln;
    c.c.writeln;
    d.c.writeln;
}

void main ()
{
    A a = new A (1), b = new A (2);
    C c = new C (3), d = new C (4);
    dump (a, b, c, d);
    true ? a = b : c = d;
//   a = c; // Error: cannot implicitly convert expression
//   c = a; // Error: cannot implicitly convert expression
    dump (a, b, c, d);
}
---

Output:

dcondo.A
dcondo.A
dcondo.C
dcondo.C
1
2
3
4
dcondo.C
dcondo.A
dcondo.C
dcondo.C
4
2
3
4



More information about the Digitalmars-d mailing list