Bug 4454 – Can't implicitly cast static arrays of primitives to immutable
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-07-13T12:09:00Z
Last change time
2012-09-09T05:03:53Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2010-07-13T12:09:39Z
Now that static arrays are value types, this should be legal because there's no mutable indirection:
void main() {
immutable uint[2] foo = getArray();
}
uint[2] getArray() {
uint[2] ret;
return ret;
}
It doesn't work on 2.047. Instead I get:
Error: cannot implicitly convert expression (getArray()) of type uint[2u] to const(immutable(uint)[])
Comment #1 by k.hara.pg — 2011-10-06T13:52:30Z
Remove dependency to std.traits.
----
private template staticLength(tuple...)
{
enum size_t staticLength = tuple.length;
}
template ReturnType(func...)
if (staticLength!(func) == 1) // (a)
{
static if (is(typeof(func) R == return))
alias R ReturnType;
else
static assert(0, "argument has no return type");
}
struct PointImpl(T)
{
@property auto test()
{
return PointImpl!int();
}
}
struct Wrapper(T)
{
T payload;
auto test()
{
//pragma(msg, ReturnType!(T.test));
//static if (is(ReturnType!(T.test))) { }
static if (is(ReturnType!(T.test) == void)) { }
return payload.test;
}
}
Wrapper!(PointImpl!int) point;
void main()
{
auto x = point.test;
}
----
A gagged forward reference error at (a) causes this problem.
Comment #2 by k.hara.pg — 2011-10-06T13:56:53Z
(In reply to comment #1)
[snip]
Sorry, I missed posting issue page. Please ignore comment #1.
Comment #3 by k.hara.pg — 2012-09-09T05:03:53Z
*** This issue has been marked as a duplicate of issue 8201 ***