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)));
> 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.
(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!
immutable(int)** and int** should also combine to const(int*)*
https://github.com/D-Programming-Language/dmd/pull/571
https://github.com/D-Programming-Language/dmd/commit/06fe1ce97ef56cb86821114024c55f8d5fe0073c