Bug 21073 – Rebindable does not work when class has alias this to inout property
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-07-25T11:44:27Z
Last change time
2021-12-14T10:34:12Z
Keywords
pull
Assigned to
No Owner
Creator
Roman
Comments
Comment #0 by freeslave93 — 2020-07-25T11:44:27Z
import std.typecons;
class Internal
{
}
class Class
{
inout(Internal) internal() inout {
return _internal;
}
alias internal this;
Internal _internal;
}
void main(string[] args)
{
const c = new Class;
auto r = c.rebindable;
}
When compiling with dmd (2.093.0) it reports the error:
/usr/include/dmd/phobos/std/typecons.d(2173): Error: pure function std.typecons.Rebindable!(const(Class)).Rebindable.RebindableCommon!(const(Class), Class, Rebindable!(const(Class))).opAssign cannot call impure delegate std.typecons.Rebindable!(const(Class)).Rebindable.RebindableCommon!(const(Class), Class, Rebindable!(const(Class))).opAssign.__lambda2
/usr/include/dmd/phobos/std/typecons.d(2173): Error: @nogc function std.typecons.Rebindable!(const(Class)).Rebindable.RebindableCommon!(const(Class), Class, Rebindable!(const(Class))).opAssign cannot call non-@nogc delegate std.typecons.Rebindable!(const(Class)).Rebindable.RebindableCommon!(const(Class), Class, Rebindable!(const(Class))).opAssign.__lambda2
main.d(20): Error: template instance std.typecons.rebindable!(const(Class)) error instantiating
This code was compilable on dmd 2.083.
Current workaround is to add 'pure' attribute to 'internal' method.
Comment #1 by Ajieskola — 2021-08-09T19:06:53Z
This is indeed a regression, but a compiler one, not a standard library one. Test case for the ultimate cause:
```d
class C
{
auto internal() const
{
return 5;
}
alias internal this;
};
void main() pure
{
const c = new C;
auto r = cast(C)c;
}
```
This should compile (I think?), but does not (since 2.084). Using `cast()` instead of `cast(C)` still works.
Comment #2 by dlang-bot — 2021-11-12T04:48:36Z
@BorisCarvajal created dlang/dmd pull request #13291 "Fix Issue 21073 - Rebindable does not work when class has alias this to inout property" fixing this issue:
- Fix Issue 21073 - Rebindable does not work when class has alias this to inout property
The cast expression was trying an 'alias this' but without error gagging.
https://github.com/dlang/dmd/pull/13291
Comment #3 by dlang-bot — 2021-11-12T08:54:24Z
dlang/dmd pull request #13291 "Fix Issue 21073 - Rebindable does not work when class has alias this to inout property" was merged into stable:
- a7ce6929f6708debfae3e3854bed5f1c02cdf1a0 by Boris Carvajal:
Fix Issue 21073 - Rebindable does not work when class has alias this to inout property
The cast expression was trying an 'alias this' but without error gagging.
https://github.com/dlang/dmd/pull/13291
Comment #4 by dlang-bot — 2021-12-14T10:34:12Z
dlang/dmd pull request #13421 "merge stable" was merged into master:
- 2367744d505cf739c90b926480e880a29a29b9e8 by Boris Carvajal:
Fix Issue 21073 - Rebindable does not work when class has alias this to inout property (#13291)
The cast expression was trying an 'alias this' but without error gagging.
https://github.com/dlang/dmd/pull/13421