On Mon, 07 Dec 2009 05:34:52 -0500, Michal Minich
<[email protected]> wrote:
Hello Tomek,
... don't make sense. So is there a reason why they aren't excluded
from the "everything in an immutable is immutable" rule?
Tomek
Immutable static member function could be useful...
marking struct or class as const or immutable is the same as marking
every its member so. The problem I see is in definition of what const or
immutable member function means:
from D specs: "Immutable member functions are guaranteed that the object
and anything referred to by the this reference is immutable."
Which applies both to instance and s static functions. I think the above
definition should apply only to instance functions. Static const or
immutable functions should be defined as:
Immutable static member functions are guaranteed that the static
variables of object and anything referred to by these variables is
immutable.
Let's say there was an immutable static member function which treated the
static data members as immutable. This means nobody else can change
them. This means that there cannot be any static member functions that
are not immutable. This means that the data members cannot be marked as
public unless they are also marked as immutable.
In this case, the equivalent thing is to mark all static data members as
immutable, and leave the static function as a normal function.
This is why the OP said they "don't make sense" Although his statement
really should be "immutable static functions don't make sense", not
"static functions in immutable types don't make sense," as they do make
sense, they should just not be marked as immutable.
The bug filed is absolutely a bug, it should be possible to have a normal
static function inside an immutable type.
-Steve