property syntax problems
Alex Burton
alexibu at mac.com
Thu Feb 5 17:35:36 PST 2009
Robert Jacques Wrote:
> On Thu, 05 Feb 2009 14:27:27 -0500, Bill Baxter <wbaxter at gmail.com> wrote:
>
> > On Fri, Feb 6, 2009 at 2:34 AM, Robert Jacques <sandford at jhu.edu> wrote:
> >> On Thu, 05 Feb 2009 06:55:46 -0500, Alex Burton <alexibu at mac.com> wrote:
> >>> int main()
> >>> {
> >>> B b;
> >>> b.a.j = 10; // error b.a is a temporary.
> >>> }
> >>
> >> This isn't a bug, it's a feature. What you wanted to use were ref
> >> returns
> >> (see http://www.digitalmars.com/d/2.0/function.html )
> >> ref A a() { return mA; }
> >
> > You could call it a bug that the compiler doesn't warn about the
> > modification of a temporary like that in a way that has no side
> > effects. Or maybe it does warn about it if you enable warnings?
> >
> > --bb
>
> Actually, from that point of view
> >>> b.a.j = 10; // error b.a is a temporary.
> isn't the real ( or I think desired ) warning. The real issue is that
> b.a.j results in an unused variable which several other compilers issue
> warnings about and is a much more general issue.
I think in this case it has to be an error, precicely because the syntax doesn't show that there is a function call.
If I do this:
x.variable() = 7;
Then I can expect it to do nothing as the parentheses show that this is a function.
If I do this:
x.variable = 7;
I expect the code to work as intended which means that :
writefln("x.variable = %d",x.variable);
should print "x.variable = 7"
And this does work as long as variable is a plain old data.
The problem occurs when variable is a struct or class.
Which allows me to type :
x.variable.i = 7
Which doesn't work as expected.
Moreover code evolving from variable being an int to a struct with two ints is common.
Alex
More information about the Digitalmars-d
mailing list