[Issue 21107] Cannot define an r/w property inside a function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 4 10:25:18 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=21107

--- Comment #3 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
There is nothing special about @property functions in terms of overload
resolution - they use the exact same code as other functions. For instance,
this is perfectly valid:

@property
int fun() { return 0; }
@property
int fun(int value) { return 1; }
@property
int fun(string value) { return 2; }

unittest {
    auto a = fun;
    fun = 13;
    fun = "twenty-seven";
}

Fixing this issue for @property functions only will require duplicating code,
complicating the compiler. It will also require fixing the exact issue in
12578, and then choosing not to apply the fix to other functions.

An argument could be made that the error message could be better. At least, it
could be made to match the error message for same-name globals:

int i;
string i; //  variable foo.i conflicts with variable foo.i at foo.d(1)

--


More information about the Digitalmars-d-bugs mailing list