[Issue 19038] Cannot compare const(T)[][] and T[][]

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 28 19:55:56 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=19038

ag0aep6g <ag0aep6g at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |ag0aep6g at gmail.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from ag0aep6g <ag0aep6g at gmail.com> ---
>From a quick glance at the source, DMD might be rejecting comparisons of arrays
that don't have a common type [1][2]. And apparently, it thinks that `Foo[][]`
and `const(Foo)[][]` don't have a common type. But that's wrong.
`const(Foo[])[]` is one.

Another symptom of that possible root cause:

----
void main()
{
    int[][] a1;
    const(int)[][] a2;
    const(int[])[] common;
    common = true ? a1 : a2; /* "Error: incompatible types" */
    /* But: */
    if (true) common = a1; else common = a2; /* correctly accepted */
    /* So there is a common type. The ternary expression should be accepted. */
}
----


[1]
https://github.com/dlang/dmd/blob/033d324957ff5bee8e25c7335eab2c562d17e2b1/src/dmd/expressionsem.d#L9059-L9066
[2]
https://github.com/dlang/dmd/blob/033d324957ff5bee8e25c7335eab2c562d17e2b1/src/dmd/dcast.d#L3339-L3344

--


More information about the Digitalmars-d-bugs mailing list