Why do I get this error when casting to an immutable or shared byRef return type?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 19 05:25:56 PDT 2016


On Sunday, 19 June 2016 at 10:45:25 UTC, Gary Willoughby wrote:
> On Sunday, 19 June 2016 at 10:35:59 UTC, Gary Willoughby wrote:
>> ...
>
> A more correct example:

In the second example, the problem is this:

alias Type = Unqual!(T);

You are declaring the function to return T, which in your example 
is either int, const(int), immutable(int), or shared(int), but 
are returning a plain int in every case. This is fine for 
const(int), since non-const can implicitly convert to const. That 
is not the case for immutable(int) or shared(int). If you take 
out the alias to Unqual!T and replace both remaining instances of 
Type with T, then it works.


More information about the Digitalmars-d-learn mailing list