Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.typecons.Rebindable / UnqualRef do not work with inout #9776

Open
dlangBugzillaToGithub opened this issue Aug 8, 2019 · 0 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

htvennik reported this on 2019-08-08T15:50:05Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=20115

Description

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.
@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants