Bug 4690 – ref return should allow assignment if not overridden
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-08-20T06:39:00Z
Last change time
2011-08-12T20:41:34Z
Keywords
rejects-valid
Assigned to
nobody
Creator
dsimcha
Comments
Comment #0 by dsimcha — 2010-08-20T06:39:19Z
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.
Comment #1 by dsimcha — 2011-08-12T20:41:34Z
Can't reproduce this anymore. Must have been fixed a long time ago.