Bug 5707 – cannot overload both property and non-property functions

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-05T16:53:24Z
Last change time
2024-12-13T17:54:57Z
Assigned to
No Owner
Creator
Jonathan M Davis
Moved to GitHub: dmd#18332 →

Comments

Comment #0 by issues.dlang — 2011-03-05T16:53:24Z
For some reason, with the current dmd, it is not legal to two overloads of a function where one is a property and one is not. I do not understand why this is so, and I've definitely run into cases where it's annoying. I'd _really_ like it to be legal to overload a function such that it's a property for one type and not for another. A prime example of this is in std.file. There are a number of property functions in there related to getting information on a file: isFile, isDir, etc. Normally, you use the version which takes a string - the path of the file. It makes perfect sense for it to be a property (e.g. if(filename.isFile){...} ). However, there are also versions of those functions which take a uint of the attributes for that file as returned by getAttributes. It makes perfect sense to have a versions of isFile, isDir, etc. which take the file attributes and tell you whether they represent a file, or directory, or whatever. However, it strikes me as undesirable (and currently illegal due to the lack of UFCS) to do something like attributes.isFile. I'd much prefer to have it called as isFile(attributes) (which is how you currently have to call it anyway). But the fact that you can't overload properties with non-properties means that for the moment, _both_ overloads of all of these functions are marked as property functions. I would _really_ like to be able to have the string functions be properties and the uint versions _not_ be properties. But the fact that dmd currently gives an error like this std/file.d(1253): Error: cannot overload both property and non-property functions when you try and do that makes it kind of hard. So, I'd _definitely_ like it if you could overload functions such that some overloads are properties and some aren't. If this isn't fixed, and we don't get UFCS before the syntax for calling @property functions is enforced, then calling the overloads for the functions in std.file which take the attributes will become illegal. Either dmd needs to be changed so that it's legal to overload property functions with non-property functions, or I'm going to have to go and change it so that isDir, isFile, etc. for attributes are renamed to something else so that they can be non-property functions.
Comment #1 by slavo5150 — 2017-08-15T05:21:48Z
Please add an example. Thanks!
Comment #2 by robert.schadek — 2024-12-13T17:54:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18332 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB