Bug 7722 – Refuse normal functions to be used as properties
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-18T05:48:00Z
Last change time
2012-03-28T12:02:33Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2012-03-18T05:48:46Z
I think this is a regression.
It was introduced by fixing bug 7670. See that for more info.
This code compiles with no errors with DMD 2.059head using the -property switch:
class Foo {}
void spam(Foo f) {}
void main() {
auto f = new Foo;
f.spam;
}
Enforce all @property attribute for property usage (with -property switch) is good, but one problem is in there.
From:
https://github.com/D-Programming-Language/dmd/pull/817#issuecomment-4580804https://github.com/D-Programming-Language/dmd/pull/817#issuecomment-4586905
> With UFCS, a property setting e1.prop = ev is rewritten to .prop(e1, ev).
> If the compiler disallows a property function with two arguments, we cannot
> set @property attribute to .prop function, but -property switch enforce to
> .prop that has @property. After all, we can never use such a syntax.
@property void prop(int, int){}
// Error: properties can only have zero or one parameter
void main(){ 1.prop = 10; }
> The alternate way is to stop property enforcement for the UFCS setter that
> needs two arguments.
/*@property */void prop(int, int){}
void main(){ 1.prop = 10; } // not detected attribute missing with -property
----
Currently, my pull in comment#1 allows a property function that has two arguments.
Comment #3 by github-bugzilla — 2012-03-19T21:57:24Z