Issue 20115 - std.typecons.Rebindable / UnqualRef do not work with inout
Summary: std.typecons.Rebindable / UnqualRef do not work with inout
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-08 15:50 UTC by Harry Vennik
Modified: 2024-12-01 16:35 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Harry Vennik 2019-08-08 15:50:05 UTC
In functions it may be necessary (e.g. for scoping reasons) to assign the return value to a variable and return it later. If the return value is a inout/const/immutable class reference, this fails (cannot modify inout/const/immutable expression...). For const/immutable this is quite easily fixed using Rebindable, but not so for inout...

----

import std.typecons : Rebindable;

class A { }

class C
{
    private A _a;

    @property const(A) aConst() const nothrow @nogc @safe
    {
         const A retVal;
         retVal = _a; // ERROR: cannot modify const expression retVal

         // in this simple case, the error could be avoided by assigning
         // directly in the declaration of retVal, but something like an
         // if or try/catch block may force to declare the variable separate
         // from assigning its value.

         return retVal;
    }

    @property const(A) aConstRebindable() const nothrow @nogc @safe
    {
         Rebindable!(const A) retVal;
         retVal = _a; // WORKS
         return retVal;
    }

    @property inout(A) aInoutRebindable() inout nothrow @nogc @safe
    {
         Rebindable!(inout A) retVal;
         retVal = _a; // ERROR: cannot modify inout expression retVal
         return retVal;
    }
}

----

Same problem with UnqualRef, which does the same, but also removes shared.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:35:23 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/9776

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB