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

           Summary: struct variable declaration and const-correctness
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Kenji Hara <[email protected]> 2013-04-29 01:29:54 PDT ---
In variable declaration, initializer should have a type that is implicitly
convertible to the required type, with the exception of the case that is an
unique expression.

But the rule is currently broken in struct object construction.
This code should raise errors in all declarations.

void main()
{
    static struct S
    {
        int[] a;
    }
    int[] marr = [1,2,3];
    immutable int[] iarr = [1,2,3];
    // mutable object should not be implicitly convertible to immutable
    immutable S i = S(marr);
    // immutable object should not be implicitly convertible to mutable
    S m = immutable S(iarr);

    static struct MS
    {
        int[] a;
        this(int n) { a = new int[](n); }
    }
    // mutable object should not be implicitly convertible to immutable
    immutable MS i = MS(3);

    static struct IS
    {
        int[] a;
        this(int n) immutable { a = new int[](n); }
    }
    // immutable object should not be implicitly convertible to mutable
    IS m = immutable IS(3);
}

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

Reply via email to