Tested with DMD 2.056.
const(int[]) x;
const(int)[] y;
static assert(is(typeof(1?x:y) == typeof(1?y:x))); // fail.
Error: static assert (is(const(int)[] == const(int[]))) is false
The static assertion should pass.
I suggest the common type in this case should be const(int)[]. That is consistent with how type combination works for basic types.
Comment #1 by hsteoh — 2014-07-19T01:44:26Z
Isn't this more a problem with type inference in the ternary '?' operator?
Comment #2 by issues.dlang — 2014-07-19T02:17:22Z
(In reply to hsteoh from comment #1)
> Isn't this more a problem with type inference in the ternary '?' operator?
Yes. The ternary operator currently, incorrectly uses the type of its last argument rather than the common type of the second and third arguments.
It's essentially the same bug as issue# 3543, but this is with arrays, whereas 3543 specifically talks about classes and interfaces, so I'm not sure if it's actually a duplicate.
Comment #3 by hsteoh — 2014-07-22T14:25:21Z
Recently Kenji fixed array type deduction to work correctly with base classes. But I guess it still doesn't work properly with common interfaces, or, in this case, const-ness.
Comment #4 by robert.schadek — 2024-12-13T17:56:54Z