Consider:
void test(int[]) {}
void main()
{
int[] a;
test(a); // fine
a.test(); // fine
a.test; // error!
}
This irregularity should be fixed. One important reason for using the property syntax is terseness.
Comment #1 by wbaxter — 2007-10-31T03:27:55Z
It's especially bad since built-in properties have the opposite restriction.
{
int[] a;
a.sort(); // error!
a.sort; // fine
}
Personally I think the () variety should be allowed for the built-in properties also.
Comment #2 by smjg — 2007-11-08T08:45:23Z
I personally think the () should be required in both cases. AISI a property can be used in four ways:
- as an lvalue
- as an rvalue
- explicitly calling it with ( )
- taking the address of the getter/setter function
Using it by itself as an ExpressionStatement is none of these.
But it certainly seems wrong that an array property can't even be used as an rvalue:
----------
int test(int[]) { return 0; }
void main()
{
int[] a;
int b;
b = test(a); // fine
b = a.test(); // fine
b = a.test; // error!
}
----------
bz1600a.d(9): Error: no property 'test' for type 'int[]'
----------
(DMD 1.023, Windows)
Comment #3 by sandford — 2009-08-03T19:17:01Z
This works in D2.031:
void foo(int[] x) {}
int main(char[][] args)
{
auto x = new int[5];
x.foo;
return 0;
}
So maybe this should be closed?