[Issue 9121] New: Templated getters/setter for properties collision

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 7 05:07:35 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9121

           Summary: Templated getters/setter for properties collision
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: dmitry.olsh at gmail.com


--- Comment #0 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2012-12-07 05:07:32 PST ---
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
        }
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list