[phobos] The @property experiment

Jonathan M Davis jmdavisProg at gmx.com
Fri Apr 8 16:34:41 PDT 2011


On 2011-04-08 15:54, Michel Fortin wrote:
> > I don't know what dmd fixes you did, but I believe there are several bugs
> > relating to @property which make it so that some things with properties
> > would become impossible. One issue which is going to require either a
> > change in dmd or Phobos is
> > http://d.puremagic.com/issues/show_bug.cgi?id=5707 . There are several
> > functions in std.file which make perfect sense as properties when they
> > take strings but don't make as much sense as properties when they take
> > an int (and _can't_ be properties without UFCS). Functions such as
> > isFile and isDir either take a string which holds a path or a uint which
> > holds the attributes of a file. The compiler currently enforces that a
> > property function is a property function for all of its overloads and
> > that doesn't work in this case. I don't know why that restriction is in
> > place (possibly because the compiler deals with property syntax _before
> > overload resolution?), but it's a problem for std.file which makes it so
> > that either those functions can't be properties, the attribute version
> > must be renamed, or dmd has to be fixed.
> 
> You can't overload properties and non-properties today; changing whether
> @property is enforced or not doesn't affect that. Fixing this problem is
> entirely orthogonal. Whether it can be fixed is unclear however
> considering that a property can return a delegate or another callable type
> which would make things ambiguous.

The problem is that isFile, isDir, etc. are currently marked as @property, because they should be properties when they take a string, but because you can't overload property functions with non-property functions, the uint versions are also marked with @property. As long as @property isn't enforced, you can continue calling the uint versions as normal functions, but once it's enforced, they become completely uncallable, because UFCS would be required to call them. So, either the compiler needs to be fixed so that the uint versions don't have to be property functions for the string versions to be property functions, or some or all of those functions in std.file need to be changed. I would much prefer that the compiler be changed, but regardless of which solution we should go with, a change _must_ be made before @property is enforced.

- Jonathan M Davis


More information about the phobos mailing list