Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
July 04, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 kinke <kinke@gmx.net> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |kinke@gmx.net --- Comment #1 from kinke <kinke@gmx.net> --- This is the behavior I would expect - a class-ref `this` is special and not to be mutated. What if `foo()` sets it to null? -- |
July 05, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 --- Comment #2 from Walter Bright <bugzilla@digitalmars.com> --- Looking into the code, the reason the match fails is because `this` for a class is considered only an rvalue, not an lvalue. -- |
July 05, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 Walter Bright <bugzilla@digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://issues.dlang.org/sh | |ow_bug.cgi?id=13116 --- Comment #3 from Walter Bright <bugzilla@digitalmars.com> --- https://issues.dlang.org/show_bug.cgi?id=13116 made class `this` not an lvalue. -- |
July 05, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 FeepingCreature <default_357-line@yahoo.de> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |default_357-line@yahoo.de --- Comment #4 from FeepingCreature <default_357-line@yahoo.de> --- I mean, in the extreme, if this was allowed, shouldn't this happen? class C { void mem() { foo(this); } } void foo(ref C c) { c = null; } C c = new C; c.mem; assert(c is null); And what about if `c` is genuinely an rvalue, such as `C createC(); createC.mem;`? -- |
July 05, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 --- Comment #5 from Walter Bright <bugzilla@digitalmars.com> --- (In reply to FeepingCreature from comment #4) > I mean, in the extreme, if this was allowed, shouldn't this happen? It isn't any different from: class C { static void mem(C c1) { foo(c1); } } void foo(ref C c2) { c2 = null; } C c3 = new C; C.mem(c3); // c1 is a copy of c3 assert(c3 is null); // c1 is set to null, not c3 > And what about if `c` is genuinely an rvalue, such as `C createC(); > createC.mem;`? Rvalues cannot be passed by ref. 13116 created a special case, and like special cases, it works inconsistently with the rest of the semantics. -- |
July 05, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 --- Comment #6 from FeepingCreature <default_357-line@yahoo.de> --- I guess I'm just allergic to ref-passing variables that you cannot see declared anywhere. In your example, C c1 is explicitly declared; in the original example, it's implicitly declared by the method call. IMO, implicitly declared variables should always be rvalues, but I guess that's a lost cause. -- |
July 05, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 --- Comment #7 from Walter Bright <bugzilla@digitalmars.com> --- Consider UFCS and the ability to do a.foo() and foo(a). When `this` behaves differently than a parameter, it generates a corner case with surprise behavior. Early on I spent much care to make the address of a nested function (i.e. a delegate) indistinguishable from the address of a member function. This symmetry and consistency turned out to be a big win. Avoiding special cases as much as possible should pay off for us. -- |
July 06, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 Adam D. Ruppe <destructionator@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |destructionator@gmail.com -- |
July 06, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |pull --- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> --- @WalterBright created dlang/dmd pull request #15389 "fix Issue 24024 - cannot pass class this to ref class" fixing this issue: - fix Issue 24024 - cannot pass class this to ref class https://github.com/dlang/dmd/pull/15389 -- |
July 06, 2023 [Issue 24024] cannot pass class this to ref class | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=24024 Dlang Bot <dlang-bot@dlang.rocks> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution|--- |FIXED --- Comment #9 from Dlang Bot <dlang-bot@dlang.rocks> --- dlang/dmd pull request #15389 "fix Issue 24024 - cannot pass class this to ref class" was merged into master: - 7d9679081f79e94793a13829e3adb54809e2da4e by Walter Bright: fix Issue 24024 - cannot pass class this to ref class https://github.com/dlang/dmd/pull/15389 -- |
Copyright © 1999-2021 by the D Language Foundation