[Issue 11343] [2.064 beta] Error: multiple field initialization

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Oct 24 17:18:08 PDT 2013


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



--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> 2013-10-24 17:18:06 PDT ---
(In reply to comment #0)
> Code:
> ----
> import std.stdio;
> 
> enum Foo {
>     A = 1,
>     B = 2
> }
> 
> struct Test {
> public:
>     const ubyte[Foo] test;
> 
>     this(Foo f) {
>         if (Foo.A & f)
>             this.test[Foo.A] = 1;
>         if (Foo.B & f)
>             this.test[Foo.B] = 2;
>     }
> }
> 
> void main() {
>     Test t = Test(Foo.A);
> }
> ----
> 
> Flag_TEst.d(16): Error: multiple field test initialization
> 
> Tested with the latest beta.
> Worked in 2.063.2

It's intended behavior change introduced by fixing bug 9665.
Non-mutable field initialization is now allowed just only once.

So, in this case, you need to create a temporary mutable AA, then initialize
Test.test by that.

struct Test {
public:
    const ubyte[Foo] test;

    this(Foo f) {
        ubyte[Foo] tmp;
        if (Foo.A & f)
            tmp[Foo.A] = 1;
        if (Foo.B & f)
            tmp[Foo.B] = 2;
        this.test = tmp;
    }
}

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