June 08, 2013
On Friday, June 07, 2013 14:53:44 Ali Çehreli wrote:
> On 06/07/2013 02:18 PM, Jonathan M Davis wrote:
> > I have an open pull request as part of the move to getting rid of
> 
> opEquals,
> 
> > opCmp, toHash, and toString from Object, and it would make it so that you
> 
> > could use something other than Object:
> I hope it supports delegate-taking toString overload for classes.[1]

It should be perfectly possible to declare such an overload now. It just won't work when used through Object. If it doesn't work, then I expect that that's a bug in formattedWrite and friends.

As far as overriding goes though, that'll depend on what the base classes of a class have declared. If they all declare toString without a delegate, then that's what you'd have to override to use toString using references of their type, whereas if they use the toString which takes a delegate, then that's what you'd have to override. But I don't see any reason that you can't have both just so long as the type of the reference that you're using has it.

Howver, I supposed that a potential problem with formattedWrite and friends is that if you have two toString methods, it has to pick which one to use, and right now, it probably just picks the one from Object. Better behavior would be to us the delegate one if it's there and fall back to the non-delegate version if it's not. Long term though, formattedWrite et al will probably have the potential of not working at all with a class if we fully remove it from Object ike we intend to, since then there's no guarantee that a class or any of its base classes have even declared any toString.

In any case, if toString with a delegate doesn't work with formattedWrite et al, then we need an enhancement request for that to be fixed.

- Jonathan M Davis
1 2
Next ›   Last »