Pure Factory Functions 💔 `inout`

Quirin Schroll qs.il.paperinik at gmail.com
Thu Feb 9 17:41:24 UTC 2023


In [Pure Factory 
Functions](https://dlang.org/spec/function.html#pure-factory-functions), it says what conversions are enabled for the result of a strongly pure function because the result is unique.

For one of my last PRs, I went through all possible combination 
of qualifiers and all pairs of these types. While I found no 
problematic conversion that was allowed, I did find conversions 
that should be allowed, but DMD rejects them. All of those 
involve `inout`; in particular, whatever of _mutable,_ `const`, 
and `immutable` you replace `inout` on both sides with (if at 
both sides), the conversion is allowed for a pure factory 
function, but not for `inout`. As far as I understand `inout`, 
this makes no sense and they should be allowed by D’s type system.

Can someone take a look at the list and tell me if I’m mistaken 
with some (or all) of them?

| “From” Type              | “To” Type                |
|--------------------------|--------------------------|
| _unshared_ `inout const` | `shared inout const`     |
| _unshared_ `inout`       | `shared inout`           |
| _unshared_ `inout`       | `shared inout const`     |
| _unshared_ `inout`       | _mutable unshared_       |
| _unshared_ `inout`       | _mutable_ `shared`       |
| _unshared_ `const`       | _unshared_ `inout const` |
| _unshared_ `const`       | `shared inout const`     |
| `shared inout const`     | _unshared_ `inout const` |
| `shared inout`           | _unshared_ `inout`       |
| `shared inout`           | _unshared_ `inout const` |
| `shared inout`           | _mutable unshared_       |
| `shared inout`           | _mutable_ `shared`       |
| `shared const`           | _unshared_ `inout const` |
| `shared const`           | `shared inout const`     |
| _mutable unshared_       | _unshared_ `inout`       |
| _mutable unshared_       | _unshared_ `inout const` |
| _mutable unshared_       | `shared inout`           |
| _mutable unshared_       | `shared inout const`     |
| _mutable_ `shared`       | _unshared_ `inout`       |
| _mutable_ `shared`       | _unshared_ `inout const` |
| _mutable_ `shared`       | `shared inout`           |
| _mutable_ `shared`       | `shared inout const`     |

[Here](https://wandbox.org/permlink/DHdKvSrfXO512Kxh) is the 
code, for those interested.


More information about the Digitalmars-d mailing list