D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7670 - UFCS problem with @property and structs
Summary: UFCS problem with @property and structs
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: pull, rejects-valid
Depends on:
Blocks:
 
Reported: 2012-03-08 05:00 UTC by bearophile_hugs
Modified: 2012-03-18 05:52 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2012-03-08 05:00:11 UTC
Modified from an example by Comrad in D.learn.


struct A {
    double x;
}
@property ref double y(ref A a) {
    return a.x;
}
void main() {
    A a1;
    a1.y() = 2.0; // OK
    a1.y = 2.0; // Error
}


DMD 2.059head gives:

test.d(10): Error: no property 'y' for type 'A', did you mean 'x'?
Comment 2 bearophile_hugs 2012-03-16 18:44:11 UTC
Maybe you have gone a bit too much far with your fix, Kenji Hara.

In my example code here I used @property:

@property ref double y(ref A a) {

But your patch allows that syntax even without @property.

Your patch allows _very_ nice and noise-free code like:

[1, 2, -3, 4].filter!(x => x > 0).map!(x => x ^^ 0.2).writeln;

But I think it undermines the meaning and usefulness of the -property compiler switch and the meaning of @property.

So I suggest to think a bit more about this, to keep the nice things, and to not throw away two baby waters.
Comment 3 bearophile_hugs 2012-03-18 05:52:43 UTC
See also Bug 7722 and Bug 7723