www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20866] New: Wrong overload function call with "scope const"

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

          Issue ID: 20866
           Summary: Wrong overload function call with "scope const"
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: apz28 hotmail.com

struct S
{
public:
    this(string s)
    {
        this.s = s;
    }

    // Remove 'const' will make it work
    void x(scope const S v)
    {
    }

    // Recursive calling itself because of alias value this - stack overflow
    private static int xCounter = 0;
    void x(string v)
    {
        assert(xCounter == 0);

        xCounter++;
        scope (exit)
            xCounter--;

        x(S(v));
    }

     property string value()
    {
        return s;
    }

    alias value this;

private:
    string s;
}

void main()
{
    S s = S("a");
    s.x("b");
}

--
May 26 2020