Bug 10005 – struct variable declaration and const-correctness
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-04-29T01:29:00Z
Last change time
2013-05-13T17:52:28Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
k.hara.pg
Comments
Comment #0 by k.hara.pg — 2013-04-29T01:29:54Z
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);
}