[Issue 24024] cannot pass class this to ref class

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jan 12 21:52:59 UTC 2024


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

ZombineDev <petar.p.kirov at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |petar.p.kirov at gmail.com
         Resolution|---                         |WONTFIX

--- Comment #14 from ZombineDev <petar.p.kirov at gmail.com> ---
Given the issues the (now reverted) dmd PR
(https://github.com/dlang/dmd/pull/15389) caused, I'd err on the side of
caution and mark this as won't fix.

Just for reference, C# (I tested .NET 8) also rejects treating `this` as an
lvalue:

```csharp
C c = new C();
c.mem();

class C
{
        public void mem()
        {
                foo(ref this);
                this = new C();
        }

        static void foo(ref C c)
        {
                c = null;
        }
}
```

Compilation error (line 8, col 11): Cannot use 'this' as a ref or out value
because it is read-only
Compilation error (line 9, col 3): Cannot assign to 'this' because it is
read-only

--


More information about the Digitalmars-d-bugs mailing list