[Issue 15507] Throwable.message() should be pure @safe

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Jan 4 14:56:56 PST 2016


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

Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang at jmdavisProg.co
                   |                            |m

--- Comment #2 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
All that pure means is that the function can't access mutable variables that
aren't passed to it. And the notion of strong vs weak purity is meaningless
aside from when optimizations can be made or the compiler can implicitly change
the mutability of the return type. And inheritance has no effect on how pure
functions work (just on whether the function is pure or not when overriding).

The this pointer/reference is one of the arguments to the function, so anything
that can be accessed via it will work, whereas something like writeln wouldn't.
And since the this pointer/reference is mutable, no optimizations of any kind
can be made based on purity. There is no "strong" purity, since not all of the
arguments are immutable.

As for your example, the one where the buffer is a member variable will work
perfectly fine. However, the one where the buffer is a static variable will not
work, because it's not passed in as a function argument (even an invisible one)
nor is it reachable via a function argument (unless the class also had a member
variable which referred to the static variable).

--


More information about the Digitalmars-d-bugs mailing list