auto x = property: variable x cannot be declared to be a function

Stewart Gordon smjg_1998 at yahoo.com
Fri Nov 24 12:01:04 PST 2006


Lionello Lunesu wrote:
> When converting a (public) variable into a property (get/set) I suddenly 
> got the compiler error mentioned in the subject.
> 
> The following code is a minimal test case:
> 
> #int prop() { return 0; }
> #void main() {
> #  auto x = prop;
> #}
<snip>
> Would it break anything to treat this case such that a property behaves 
> more like a variable, meaning that the type deferred would be the return 
> type of the getter?

No.  AIUI property getting is what your code is supposed to do.

A function name by itself has no meaning without context.  There are 
four ways in which it can gain meaning from context:

(a) calling the function explicitly, using ()
(b) taking the function's address, using &
(c) setting the property, by putting it on the left-hand side of an =
(d) getting the property, by using it in an expression anywhere where a 
value is required.

The problem appears to be that, in this context, the compiler fails to 
detect the context before trying to process the declaration.  Really, 
using it as an initializer, whether in an auto declaration or one of 
specified type, should be an instance of (d).

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- 
PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.



More information about the Digitalmars-d-bugs mailing list