http://d.puremagic.com/issues/show_bug.cgi?id=4690

           Summary: ref return should allow assignment if not overridden
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: dsim...@yahoo.com


--- Comment #0 from David Simcha <dsim...@yahoo.com> 2010-08-20 06:39:19 PDT ---
struct Foo {
    uint num;

    @property ref uint front() {
        return num;
    }

    ref uint opIndex(size_t index) {
        return num;
    }
}

void main() {
    Foo foo;
    foo.front++;       // Works
    foo.front += 1;    // error 1
    foo.front = 1;     // error 2
    foo[0] = 1;        // error 3
}

If something returns by reference then it should be usable for assignment,
though if the class/struct contains an explicit setter property or
opIndexAssign, this should override assignment via ref return.  Here are the
error messages produced.

test9.d(16): Error: 'foo.front' is not a scalar, it is a @property ref uint()
test9.d(16): Error: incompatible types for ((foo.front) += (1)): '@property ref
uint()' and 'int'
test9.d(17): Error: function test9.Foo.front () is not callable using argument
types (int)
test9.d(17): Error: expected 0 arguments, not 1 for non-variadic function type
@property ref uint()
test9.d(18): Error: operator [] assignment overload with opIndex(i, value)
illegal, use opIndexAssign(value, i)

I'm aware that other bugs have reported bits and pieces of this problem, but I
think this is a clearer bug report on the more general issue.  Also, marking as
major because it's a significant impedement to library development in
std.range.

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

Reply via email to