[Issue 10005] New: struct variable declaration and const-correctness

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 29 01:29:56 PDT 2013


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: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 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: -------


More information about the Digitalmars-d-bugs mailing list