D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6940 - immutable(int*)*/immutable(int)** and int** do not combine
Summary: immutable(int*)*/immutable(int)** and int** do not combine
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2011-11-12 13:34 UTC by timon.gehr
Modified: 2011-12-20 13:03 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description timon.gehr 2011-11-12 13:34:54 UTC
immutable(int*)* and int** do not combine even though const(int*)* would be a common type:

immutable(int*)*    x;
int**               y;

static assert(is(typeof(x) : const(int*)*)); // ok
static assert(is(typeof(y) : const(int*)*)); // ok
static assert(is(typeof(1?x:y)));            // fail


Compare to dynamic arrays:

immutable(int[])[]  a;
int[][]             b;

static assert(is(typeof(a) : const(int[])[])); // ok
static assert(is(typeof(b) : const(int[])[])); // ok
static assert(is(typeof(1?a:b)));              // ok

(why on earth do the two cases use different logic?)

Therefore the following could be used as a workaround:

static assert(is(typeof((1?x[0..1]:y[0..1]).ptr)));
Comment 1 Kenji Hara 2011-11-16 19:44:01 UTC
> static assert(is(typeof(x) : const(int*)*)); // ok

> static assert(is(typeof(a) : const(int[])[])); // ok

I think these two lines should not compile.
They are the part of bug 4251.

Then, Both two cases should not have common type, IMO.
Comment 2 timon.gehr 2011-11-17 11:40:16 UTC
(In reply to comment #1)
> > static assert(is(typeof(x) : const(int*)*)); // ok
> 
> > static assert(is(typeof(a) : const(int[])[])); // ok
> 
> I think these two lines should not compile.
> They are the part of bug 4251.
> 
> Then, Both two cases should not have common type, IMO.

No, they are not part of bug 4251. This bug report is valid.

This is bug 4251:

immutable(int)** x;
immutable(int)[][] y;

static assert(is(typeof(x): const(int)**));
static assert(is(typeof(y): const(int)[][]));

Consider this:

immutable(int)** x;
int y;
// we now make *x point to y, even though y is not immutable:
const(int)** p = x; // bug 4251
*p=&y; // since p == x, this assigns &y to *x

That only works because immutable converted to const _two references deep_.

None of that is going on here, consider this:

immutable(int*)* x
int y;
// we now try to do the same thing
const(int*)* p = x; // assume this works
*p = y; // error!
Comment 3 timon.gehr 2011-11-18 13:35:48 UTC
immutable(int)** and int** should also combine to const(int*)*