[Issue 1604] Non-final method on final struct is too restrictive

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 11 08:07:54 PDT 2008


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


smjg at iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
           Keywords|rejects-valid               |




------- Comment #3 from smjg at iname.com  2008-09-11 10:07 -------
I'm somewhat confused.  Firstly, all documentation of final as a storage class
seems to have vanished, apart from the seemingly orphaned page
http://www.digitalmars.com/d/final-const-invariant.html

Secondly, that page and the current page
http://www.digitalmars.com/d/2.0/const3.html
alike state

"Const member functions are functions that are not allowed to change any part
of the object through the member function's this reference."

Nothing about changing other data pointed to through the object.  Thus const
functions semantically match the final storage class, and invariant functions
semantically match the const storage class.  (DMD 2.019 doesn't seem to
implement it correctly though - but that's another matter.)  Thus according to
the current spec, if the function doesn't modify anything through this, it
should be declared as invariant, rather than const.  No need for the compiler
to second-guess by examining the function source.  So according to this
principle, the callability rules should be:

|        function is ->  mutable  const  invariant
v this is
mutable                  yes      yes    yes
final                    no       yes    yes
const                    no       yes    yes
invariant                no       yes    yes

I'm not sure what was actually intended.  Really, const, final and invariant
should all be available as function storage classes, and match the .  The
problem is that final as a function attribute is already taken, but that
shouldn't stop it working with "final" placed between the parameter list and
the '{'.  By this, the callability rules would be

|        function is ->  mutable  final  const  invariant
v this is
mutable                  yes      yes    yes    no
final                    no       yes    yes    no
const                    no       no     yes    no
invariant                no       no     yes    yes

What should we do?


-- 



More information about the Digitalmars-d-bugs mailing list