[Issue 20517] New: Const'ness and delegate implicit conversion problems

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 18 04:25:56 UTC 2020


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

          Issue ID: 20517
           Summary: Const'ness and delegate implicit conversion problems
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

>From Timon Gehr

https://digitalmars.com/d/archives/digitalmars/D/Constness_and_delegates_334566.html

-------------------------------------
This should compile:

void main(){
    immutable(void*) a;
    void* b=a; // this is rejected incorrectly
    // TODO: add other qualifier combinations
}

This should compile too:

void main(){
    int delegate()const dgc;
    int delegate() dgc2=dgc; // this is correctly accepted
    int delegate()immutable dgi;
    int delegate() dgi2=dgi; // this is rejected incorrectly
    int delegate() dgi3=()=>dgi(); // ugly workaround
    int delegate()shared dgs;
    int delegate() dgs2=dgs; // this is rejected incorrectly
    int delegate() dgs3=()=>dgs(); // ugly workaround
    // TODO: add all other qualifier combinations
}


Exhaustive tests for checks on nested function contexts:

void fun(inout(int)*){
    int* x;
    const(int*) cx;
    immutable(int*) ix;
    shared(int*) sx;
    shared(const(int*)) scx;
    inout(int*) wx;
    shared(inout(int*)) swx;
    const(inout(int*)) cwx;
    shared(const(inout(int*))) scwx;
    void foo(){
        int* x=x;
        const(int)* cx=cx; // ok
        immutable(int)* ix=ix; // ok
        shared(int)* sx=sx; // ok
        shared(const(int*)) scx=scx; // ok
        inout(int)* wx=wx; // ok
        shared(inout(int))* swx=swx; // ok
        const(inout(int))* cwx=cwx; // ok
        shared(const(inout(int)))* scwx=scwx; // ok
    }
    void fooc()const{
        int* x=x; // currently ok, shouldn't compile
        const(int)* x2=x; // ok
        const(int)* cx=cx; // ok
        immutable(int)* ix=ix; // ok
        shared(int)* sx=sx; // currently ok, shouldn't compile
        const(shared(int))* sx2=sx; // ok
        shared(const(int*)) scx=scx; // ok
        inout(int)* wx=wx; // currently ok, shouldn't compile
        const(inout(int))* wx2=wx; // ok
        shared(inout(int))* swx=swx; // currently ok, shouldn't compile
        shared(const(inout(int)))* swx2=swx; // ok
        const(inout(int))* cwx=cwx; // ok
        shared(const(inout(int)))* scwx=scwx; // ok
    }
    void fooi()immutable{
        //int* x=x; // error, correct
        //const(int)* cx=cx; // error, correct
        immutable(int)* ix=ix; // ok
        //shared(int)* sx=sx; // error, correct
        //shared(const(int*)) scx=scx; // error, correct
        //inout(int)* wx=wx; // error, correct
        //shared(inout(int))* swx=swx; // error, correct
        //const(inout(int))* cwx=cwx; // error, correct
        //shared(const(inout(int)))* scwx=scwx; // error, correct
    }
    void foos()shared{
        //int* x=x; // error, correct
        //const(int)* cx=cx; // error, correct
        immutable(int)* ix=ix; // ok
        shared(int)* sx=sx; // ok
        shared(const(int*)) scx=scx; // ok
        //inout(int)* wx=wx; // error, correct
        //shared(inout(int))* swx=swx; // currently error, should work
        //const(inout(int))* cwx=cwx; // error, correct
        //shared(const(inout(int)))* scwx=scwx; // currently error, should work
    }
    void foosc()shared const{
        //int* x=x; // error, correct
        //const(int)* cx=cx; // error, correct
        immutable(int)* ix=ix; // ok
        //shared(int)* sx=sx; // error, correct
        //const(shared(int))* sx2=sx; // currently error, should work
        shared(const(int*)) scx=scx; // ok
        //inout(int)* wx=wx; // error, correct
        //const(inout(int))* wx2=wx; // currently error, should work
        //shared(inout(int))* swx=swx; // error, correct
        //const(shared(inout(int)))* swx2=swx; // currently error, should work
        //const(inout(int))* cwx=cwx; // error, correct
        //shared(const(inout(int)))* scwx=scwx; // currently error, should work
    }
    void foow()inout{
        int* x=x; // currently ok, shouldn't compile
        immutable(int)* ix=ix; // ok
        shared(int)* sx=sx; // currently ok, shouldn't compile
        inout(int)* wx=wx; // ok
        shared(inout(int))* swx=swx; // ok
        const(inout(int))* cwx=cwx; // ok
        shared(const(inout(int)))* scwx=scwx; // ok
    }
    void foosw()shared inout{
        //int* x=x; // error, correct
        immutable(int)* ix=ix; // ok
        //shared(int)* sx=sx; // error, correct
        //inout(int)* wx=wx; // error, correct
        shared(inout(int))* swx=swx; // ok
        //const(inout(int))* cwx=cwx; // error, correct
        shared(const(inout(int)))* scwx=scwx; // ok
    }
    void fooscw()shared const inout{
        //int* x=x; // error, correct
        immutable(int)* ix=ix; // ok
        //shared(int)* sx=sx; // error, correct
        //inout(int)* wx=wx; // error, correct
        //shared(inout(int))* swx=swx; // error, correct
        //const(shared(inout(int)))* swx2=swx; // currently error, should
compile
        //const(inout(int))* cwx=cwx; // error, correct
        shared(const(inout(int)))* scwx=scwx; // ok
    }
}

void fun(inout(int)*){
    void bar(){}
    void barc()const{}
    void bari()immutable{}
    void bars()shared{}
    void barsc()shared const{}
    void barw()inout{}
    void barsw()shared inout{}
    void barcw()const inout{}
    void barscw()shared const inout{}
    void foo(){
        bar(); // ok
        barc(); // ok
        bari(); // ok
        bars(); // ok
        barsc(); // ok
        barsw(); // ok
        barcw(); // ok
        barscw(); // ok
    }
    void fooc()const{
        bar(); // currently ok, shouldn't compile
        barc(); // ok
        bari(); // ok
        bars(); // currently ok, shouldn't compile
        barsc(); // ok
        barsw(); // currently ok, shouldn't compile
        barcw(); // ok
        barscw(); // ok
    }
    void fooi()immutable{
        bar(); // currently ok, shouldn't compile
        barc(); // currently ok, shouldn't compile
        bari(); // ok
        bars(); // currently ok, shouldn't compile
        barsc(); // currently ok, shouldn't compile
        barsw(); // currently ok, shouldn't compile
        barcw(); // currently ok, shouldn't compile
        barscw(); // currently ok, shouldn't compile
    }
    void foos()shared{
        bar(); // currently ok, shouldn't compile
        barc(); // currently ok, shouldn't compile
        bari(); // ok
        bars(); // ok
        barsc(); // ok
        barsw(); // ok
        barcw(); // currently ok, shouldn't compile
        barscw(); // ok
    }
    void foosc()shared const{
        bar(); // currently ok, shouldn't compile
        barc(); // currently ok, shouldn't compile
        bari(); // ok
        bars(); // currently ok, shouldn't compile
        barsc(); // ok
        barsw(); // currently ok, shouldn't compile
        barcw(); // currently ok, shouldn't compile
        barscw(); // ok
    }
    void foow()inout{
        bar(); // currently ok, shouldn't compile
        barc(); // currently ok, shouldn't compile
        bari(); // ok
        bars(); // currently ok, shouldn't compile
        barsc(); // currently ok, shouldn't compile
        barsw(); // ok
        barcw(); // ok
        barscw(); // ok
    }
    void foosw()shared inout{
        bar(); // currently ok, shouldn't compile
        barc(); // currently ok, shouldn't compile
        bari(); // ok
        bars(); // currently ok, shouldn't compile
        barsc(); // currently ok, shouldn't compile
        barsw(); // ok
        barcw(); // currently ok, shouldn't compile
        barscw(); // ok
    }
    void fooscw()shared const inout{
        bar(); // currently ok, shouldn't compile
        barc(); // currently ok, shouldn't compile
        bari(); // ok
        bars(); // currently ok, shouldn't compile
        barsc(); // currently ok, shouldn't compile
        barsw(); // currently ok, shouldn't compile
        barcw(); // currently ok, shouldn't compile
        barscw(); // ok
    }
}

--


More information about the Digitalmars-d-bugs mailing list