Bug 9121 – Templated getters/setter for properties collision
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-12-07T05:07:00Z
Last change time
2013-09-09T10:32:08Z
Assigned to
nobody
Creator
dmitry.olsh
Comments
Comment #0 by dmitry.olsh — 2012-12-07T05:07:32Z
Sample:
struct A
{
size_t foo(){
length!1 = 22; //expect to call a setter
return length!0; //expect to call a getter
}
@property size_t length(size_t n)()const{ return n; }
@property void length(size_t n)(size_t new_size){
//set new size
}
}
Instead of expected call issued the compiler spits out:
prop_bug.d(5): Error: template prop_bug.A.length matches more than one template length(uint n)() and prop_bug.d(11):length(uint n)(size_t new_size)
prop_bug.d(6): Error: template prop_bug.A.length matches more than one template declaration, prop_bug.d(9):length(uint n)() and prop_bug.d(11):length(uint n)(size_t new_size)
Curiously if I (not using -property switch) change length!0 to length!0() it compiles.
Tested on the dmd 2.061 from git-hub master 143e02d2b1fdb990cab3c6039c7459be3e90e142.
Putting both in a single template also works i.e. the following:
struct A
{
size_t foo(){
length!1 = 22;
return length!0;
}
template length(size_t n)
{
@property size_t length()const{ return n; }
@property void length(size_t new_size){
//set new size
}
}
}