← Back to index
|
Original Bugzilla link
Bug 19038 – Cannot compare const(T)[][] and T[][]
Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-28T14:10:31Z
Last change time
2024-12-13T18:59:22Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#19451 →
Comments
Comment #0
by default_357-line — 2018-06-28T14:10:31Z
This code works: [cast(const) "a"] == ["a"]; This code doesn't work. [[cast(const) "a"]] == [["a"]];
Comment #1
by ag0aep6g — 2018-06-28T19:55:56Z
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
Comment #2
by default_357-line — 2018-06-29T08:18:41Z
Just casting both sides to const seems to work.
https://github.com/dlang/dmd/pull/8413
Comment #3
by robert.schadek — 2024-12-13T18:59:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/19451
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB