[Issue 22509] New: Invalid implicit conversion from int* to immutable(int*)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Nov 13 08:44:54 UTC 2021


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 at puremagic.com
          Reporter: thomas.bockman at 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*)`

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

--


More information about the Digitalmars-d-bugs mailing list