auto x = property: variable x cannot be declared to be a function
Dave
Dave_member at pathlink.com
Fri Nov 24 17:01:08 PST 2006
Stewart Gordon wrote:
> 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).
>
I think you're right - this is a bug. Besides which, it's inconsistent since the requirement to use
() to call any [non function literal] function with an empty parameter list was dropped months ago.
Has this been added to bugzilla?
Thanks,
- Dave
> Stewart.
>
More information about the Digitalmars-d-bugs
mailing list