www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Possible lvalue vs rvalue bug with struct?

reply Kevin Bealer <Kevin_member pathlink.com> writes:
I get the error:

ut_wrapper.d(38): ranges.opIndex(i) is not an lvalue

A. Line 38 is marked.
B. If ranges is made into a "class" the issue disappears.
C. If the expression is seperated, the issue disappears.
D. But changing the name "length" (in range.length) doesn't affect it.

:
: import std.stdio;
: 
: //class range {  // B
: struct range {
:     size_t begin;
:     size_t end;
:     
:     int length() // D
:     {
:         return end-begin;
:     }
: }
: 
: class Container {
:     range opIndex(size_t i)
:     in
:     {
:         assert(i < data.length);
:     }
:     body
:     {
:         return data[i];
:     }
:     
: private:
:     range[] data;
: }
: 
: int main()
: {
:     Container ranges;
:     
:     size_t i = 0;
:     
:     //range r = ranges[i];   // C
:     //if (r.length == 1) {   // C
:     if (ranges[i].length == 1) {  // A. LINE 38
:         writefln("range==1");
:     }
:     
:     return 0;
: }
: 

Kevin
Apr 24 2005
next sibling parent reply Derek Parnell <derek psych.ward> writes:
On Sun, 24 Apr 2005 23:30:56 +0000 (UTC), Kevin Bealer wrote:

 I get the error:
 
 ut_wrapper.d(38): ranges.opIndex(i) is not an lvalue
 
[snip] I cannot reproduce that error with the code you gave us. Here is your code with a couple of changes to get it to run okay. The changes are marked with //DJP but they shouldn't have influenced the reported error. // --------------------------- import std.stdio; struct range { size_t begin; size_t end; int length() // D { return end-begin; } } class Container { range opIndex(size_t i) in { assert(i < data.length); } body { return data[i]; } // DJP To get at least one range to test. void AddRange(size_t b, size_t e) { data.length = data.length + 1; data[$-1].begin = b; data[$-1].end = e; } private: range[] data; } int main() { Container ranges = new Container; //DJP ranges.AddRange(2,6); //DJP size_t i = 0; if (ranges[i].length == 1) { writefln("range==1"); } return 0; } // --------------------------- -- Derek Parnell Melbourne, Australia 25/04/2005 9:57:21 AM
Apr 24 2005
parent Kevin Bealer <Kevin_member pathlink.com> writes:
In article <fcl7wqonidem$.wcyai42foe58.dlg 40tude.net>, Derek Parnell says...
On Sun, 24 Apr 2005 23:30:56 +0000 (UTC), Kevin Bealer wrote:

 I get the error:
 
 ut_wrapper.d(38): ranges.opIndex(i) is not an lvalue
 
[snip] I cannot reproduce that error with the code you gave us. Here is your code with a couple of changes to get it to run okay. The changes are marked with //DJP but they shouldn't have influenced the reported error.
(snip) I actually hadn't thought to run the program (I'm working with a larger project and this is a boil-down of an error I saw). The error I got was at compile time. I checked the compile options, and the error goes away if "-inline" is not specified. This is with version 0.121. Kevin
Apr 24 2005
prev sibling parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Kevin Bealer schrieb am Sun, 24 Apr 2005 23:30:56 +0000 (UTC):
 I get the error:

 ut_wrapper.d(38): ranges.opIndex(i) is not an lvalue

 A. Line 38 is marked.
 B. If ranges is made into a "class" the issue disappears.
 C. If the expression is seperated, the issue disappears.
 D. But changing the name "length" (in range.length) doesn't affect it.

:
: import std.stdio;
: 
: //class range {  // B
: struct range {
:     size_t begin;
:     size_t end;
:     
:     int length() // D
:     {
:         return end-begin;
:     }
: }
: 
: class Container {
:     range opIndex(size_t i)
:     in
:     {
:         assert(i < data.length);
:     }
:     body
:     {
:         return data[i];
:     }
:     
: private:
:     range[] data;
: }
: 
: int main()
: {
:     Container ranges;
:     
:     size_t i = 0;
:     
:     //range r = ranges[i];   // C
:     //if (r.length == 1) {   // C
:     if (ranges[i].length == 1) {  // A. LINE 38
:         writefln("range==1");
:     }
:     
:     return 0;
: }
: 

 Kevin
Added to DStress as http://dstress.kuehne.cn/run/opIndex_01.d http://dstress.kuehne.cn/run/opIndex_02.d http://dstress.kuehne.cn/run/opIndex_03.d http://dstress.kuehne.cn/run/opIndex_04.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCbIRN3w+/yD4P9tIRAvm7AKCaqUcjNOqYTKSXPlsljJJJD/sYHgCeMtye oNIZ1Aq0gtbvkmqURPZ5fus= =FU0V -----END PGP SIGNATURE-----
Apr 24 2005