www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - No property error message

reply ric maicle <rmaicle gmail.com> writes:
I got an error message with the following code saying:

   Error: no property 'length' for type 'int[string]'

Shouldn't the error message say 'length()'?

~~~
import std.stdio;

void main() {
   int[string] a;
   a["one"] = 1;
   a["two"] = 2;
   a["three"] = 3;
   auto len = a.length();
}
~~~

DMD 2.070.2
Mar 19 2016
next sibling parent JR <sunspyre gmail.com> writes:
On Saturday, 19 March 2016 at 18:36:10 UTC, ric maicle wrote:
 I got an error message with the following code saying:

   Error: no property 'length' for type 'int[string]'

 Shouldn't the error message say 'length()'?

 ~~~
 import std.stdio;

 void main() {
   int[string] a;
   a["one"] = 1;
   a["two"] = 2;
   a["three"] = 3;
   auto len = a.length();
 }
 ~~~

 DMD 2.070.2
Well, if we think of it as separate steps, resolving the function "length" is what's failing here. The subsequent () would just call it, if it existed, but the name of the property/symbol would still be "length". But yes; you could make a case that, in the case of invalid function calls, it should include the whole erroneous attempted function signature in the error message. I can imagine it becoming ambiguous once templates enter the picture however, and for not much gain.
Mar 19 2016
prev sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 3/19/16 2:36 PM, ric maicle wrote:
 I got an error message with the following code saying:

    Error: no property 'length' for type 'int[string]'

 Shouldn't the error message say 'length()'?
No, it should say length is a property, not a function. a.length should work. Note the error message here: struct S { int x; } void main() { S s; s.x(); } function expected before (), not s.x of type int Please file a bug report. -Steve
Mar 21 2016