www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3973] New: out contracts fail with ref return types

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3973

           Summary: out contracts fail with ref return types
           Product: D
           Version: 2.041
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: lat7h virginia.edu



20:23:53 PDT ---
The following does not compile:
----
ref int buggy(ref int x) 
out(result){ }
body { return ++x; }
----
bug.d(3): Error: result = (x += 1) is not mutable
bug.d(3): Error: result = (x += 1) is not an lvalue

The first of these statements comes because out contracts are always const
(func.c:1111) and thus not mutable.
The second comes from statement:3488 where we try to make an assignment
expression (created on statement.c:3490) into an lvalue, which assignment
expressions are not.


Reading through the source, I think what is going on is that
----
    out(x) { Y }
    ...
    return Z
----
is replaced with
----
    const nonref typeof(return) x; // statment.c:3488, func.c:1107..1124
    lvalue(x = Z);  // statement.c:3490, 3500
    goto __returnLabel; // statement.c:3536
__returnLabel:
    void __ensure(ref typeof(return) x) { Y } // func.c:713..738
    __ensure(x);
----
I probably got some of this wrong; I'm not familiar with most of this code.

It's not clear to me why we don't instead do
----
    typeof(return) __ensure(const typeof(return) x) { Y cast(typeof(return))x;
}
    return __ensure( Z )
----
which seems at least superficially simpler.

I discovered this issue while trying to understand issue 3667, and suspect
without evidence that the two might be related.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 15 2010
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3973


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |k.hara.pg gmail.com
         Resolution|                            |DUPLICATE



*** This issue has been marked as a duplicate of issue 3273 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 18 2011