[Issue 22509] Document implicit conversion to immutable for pure factory functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Mar 5 15:44:26 UTC 2023


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

Nick Treleaven <nick at geany.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |nick at geany.org
         Resolution|---                         |INVALID

--- Comment #3 from Nick Treleaven <nick at geany.org> ---
>    immutable immutA = a.ptr; // Accepts invalid!

That is valid. A.ptr is a template so it gets attributes inferred (see below).

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

This error goes away if you add `pure` to B.ptr.

> this is a deliberate feature not yet documented in the spec

It is documented:
dlang.org/spec/function.html#pure-factory-functions

If you have any ideas on how the docs can be improved please let us know.

--


More information about the Digitalmars-d-bugs mailing list