www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22509] New: Invalid implicit conversion from int* to

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

          Issue ID: 22509
           Summary: Invalid implicit conversion from int* to
                    immutable(int*)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: thomas.bockman gmail.com

`immutable immutA = a.ptr;` should be a compile-time error, just like
`immutable immutB = b.ptr;` is:

//////////////////////////////////////////////////////////
module app;

struct A(P) {
    P ptr() inout  safe {
        return null; }
}

struct B {
    int* ptr() inout  safe {
        return null; }
}

void main()  safe {
    immutable A!(int*) a;
    immutable immutA = a.ptr; // Accepts invalid!

    immutable B b;
    immutable immutB = b.ptr; // Error: cannot implicitly convert expression
`b.ptr()` of type `int*` to `immutable(int*)`

}
//////////////////////////////////////////////////////////

--
Nov 13 2021