D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3221 - (D1 only) Can't use property syntax with ufcs
Summary: (D1 only) Can't use property syntax with ufcs
Status: RESOLVED DUPLICATE of issue 2883
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2009-08-01 03:50 UTC by John Chapman
Modified: 2012-02-02 01:52 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description John Chapman 2009-08-01 03:50:20 UTC
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 John Chapman 2009-08-01 03:52:51 UTC
(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 Witold Baryluk 2010-02-05 06:22:09 UTC
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 Witold Baryluk 2010-02-05 06:24:01 UTC
Similary to the bug3771
Comment 4 yebblies 2012-02-01 07:33:23 UTC
Works in D2 (2.058)
Comment 5 yebblies 2012-02-02 01:52:09 UTC

*** This issue has been marked as a duplicate of issue 2883 ***