Bug 23273 – [REG2.095] Error on passing inout variable to function (not an lvalue)

Status
NEW
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-07-29T22:36:24Z
Last change time
2024-12-13T19:23:59Z
Keywords
industry, rejects-valid
Assigned to
No Owner
Creator
johanengelen
Moved to GitHub: dmd#18118 →

Comments

Comment #0 by johanengelen — 2022-07-29T22:36:24Z
Testcase: ``` struct Bug(V) { struct Cell { } void getCell(ref inout(Cell) *) inout { } void locate() inout { inout(Cell) * cell; getCell(cell); } } struct StructAlias(alias toRef) {} struct S(T) { void foo() {} alias RangesList = StructAlias!(foo); Bug!(RangesList) bins; } S!uint a; ``` Compiling with dlang2.094 succeeds Compiling with dlang2.095 gives the error: ``` bug.d(8): Error: `cast(inout(Cell)*)cell` is not an lvalue and cannot be modified bug.d(17): Error: template instance `bug.Bug!(StructAlias!(foo))` error instantiating bug.d(20): instantiated from here: `S!uint` ``` A workaround to have this code compile with dlang2.100 would be appreciated.
Comment #1 by maxhaton — 2022-07-31T03:06:44Z
Appears to be due to a difference in the .deco of each type despite them being the same according to toChars()
Comment #2 by johanengelen — 2022-07-31T10:38:54Z
Digger says it is introduced by: https://github.com/dlang/dmd/pull/10124
Comment #3 by kinke — 2022-07-31T15:23:48Z
I bet that PR just uncovered another issue, and the relevant questions IMO are: a) Why is there a cast in the 1st place? When removing the `ref`, the `-vcg-ast` output reveals a silly inout pure nothrow @nogc @safe void locate() { inout(Cell)* cell = null; this.getCell(cast(inout(Cell)*)cell); } b) Why aren't the 2 types equivalent, where CastExp.isLvalue() would return true? https://github.com/dlang/dmd/blob/f282f98f7b8cadd4e37fb95c78d3590756f817e7/src/dmd/expression.d#L5389
Comment #4 by kinke — 2022-07-31T15:30:53Z
... bringing us back to Max's reply that I've overlooked. ;) - Probably some missing Type.merge() somewhere, causing the missing equivalence and so the cast in the first place.
Comment #5 by maxhaton — 2022-07-31T16:28:55Z
I concur with both points
Comment #6 by robert.schadek — 2024-12-13T19:23:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18118 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB