Bug 3221 – (D1 only) Can't use property syntax with ufcs
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2009-08-01T03:50:00Z
Last change time
2012-02-02T01:52:09Z
Keywords
rejects-valid
Assigned to
nobody
Creator
johnch_atms
Comments
Comment #0 by johnch_atms — 2009-08-01T03:50:20Z
Free functions can be used as methods of an array if the first argument in the function definition is an array. For example:
int indexOf(T)(T[] array, T value) {...}
int[] ints = getInts();
int i = ints.indexOf(2);
However, when the array argument is called without parameters, the expression fails to compile, as this example shows.
string[] split(string s, string sep) { ... }
class Person {
string name_;
string name() { return name_; }
}
auto person = getPerson();
string[] firstAndLast = person.name.split(" ");
The above line will only compile if it is changed to:
string[] firstAndList = person.name().split(" ");
Comment #1 by johnch_atms — 2009-08-01T03:52:51Z
(In reply to comment #0)
> Free functions can be used as methods of an array if the first argument in the
> function definition is an array. For example:
> int indexOf(T)(T[] array, T value) {...}
> int[] ints = getInts();
> int i = ints.indexOf(2);
> However, when the array argument is called without parameters, the expression
> fails to compile, as this example shows.
> string[] split(string s, string sep) { ... }
> class Person {
> string name_;
> string name() { return name_; }
> }
> auto person = getPerson();
> string[] firstAndLast = person.name.split(" ");
> The above line will only compile if it is changed to:
> string[] firstAndList = person.name().split(" ");
Oops, I meant to say: However, when the array argument is called without parentheses, the expression fails to compile...
Comment #2 by witold.baryluk+d — 2010-02-05T06:22:09Z
One should possibly add @property for such function, so it will be possible tu use such function not only as method but also as getter. Unfortunetly it isn't yet implemented.
Comment #3 by witold.baryluk+d — 2010-02-05T06:24:01Z
Similary to the bug3771
Comment #4 by yebblies — 2012-02-01T07:33:23Z
Works in D2 (2.058)
Comment #5 by yebblies — 2012-02-02T01:52:09Z
*** This issue has been marked as a duplicate of issue 2883 ***