[Issue 3221] New: Array extension methods require parentheses

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Aug 1 03:50:21 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3221

           Summary: Array extension methods require parentheses
           Product: D
           Version: 2.032
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: johnch_atms at hotmail.com


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(" ");

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list