[phobos] Time to get ready for the next release

Robert Jacques sandford at jhu.edu
Fri Apr 22 11:55:14 PDT 2011


On Fri, 22 Apr 2011 14:20:21 -0400, Robert Jacques <sandford at jhu.edu>  
wrote:

> On Fri, 22 Apr 2011 13:22:31 -0400, Steve Schveighoffer  
> <schveiguy at yahoo.com> wrote:
>>> From: Robert Jacques <sandford at jhu.edu>
> [snip]
>>> Forth, came the realization that in D2 'seconds' would probably be  
>>> pure, which would cause s.seconds = 5 to be compiler error.
>>
>> No, it wouldn't be an error.  s.seconds(5) is exactly the same as  
>> TimeSpan.seconds(5), both would be callable as pure functions.  In  
>> other words, s isn't actually passed to the function, it's just used as  
>> a namespace.
>
> I apologize, pure alone wouldn't be enough to cause a compiler error. I  
> was thinking of the fact that DMD could/does error on expressions which  
> do nothing. However, pure wouldn't be enough to let the compiler know  
> 'seconds = 5' does nothing. It would probably take a combination of  
> const/immutable + pure + nothrow, for DMD to detect that s.seconds = 5  
> could not possible produce useful work, and therefore should error.

P.S. On third thought, you'd really only need a const/immutable method, as  
assignment of const/immutable variables is invalid. (This would require a  
heuristic in DMD, etc). Also, given we can have static variables, static  
methods should also be able to be const/immutable. But since static  
variables are considered global state, perhaps pure covers those use  
cases. Hmm... so maybe I was correct in that a strongly-pure function  
called with field syntax should always be an error.


More information about the phobos mailing list