https://issues.dlang.org/show_bug.cgi?id=12777

--- Comment #5 from Ivan Kazmenko <ga...@mail.ru> ---
(In reply to Andrej Mitrovic from comment #2)
> (In reply to Ivan Kazmenko from comment #0)
> > First, member "v" is not constant - the method is.
> 
> No, it's not the 'method', it's the 'this' reference which is constant. And
> const is transitive in D, which means all fields are constant. The above is
> equivalent to:
> 
> -----
> struct S {
>     const(int) v;  // as seen from 'fun'
>     void fun () const {v++;}
> }
> 
> struct S {
>     immutable(int) v;  // as seen from 'fun'
>     void fun () immutable {v++;}
> }
> -----
> 
> However I do agree the diagnostic could be improved a bit.

Thank you for the explanation!  I see now how it makes sense from the
compiler's point of view.  For the programmer however, it is convenient (and
"safe", right?) to reason as "method is constant means it can not modify its
object", and reading the current message somewhat breaks that model of
thinking.

--

Reply via email to