[Issue 20138] is expression not evaluating correctly?

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Aug 18 21:54:54 UTC 2019


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

--- Comment #6 from ag0aep6g <ag0aep6g at gmail.com> ---
(In reply to Manu from comment #4)
>   T fun(T)(shared(T) a)
>   {
>       return a;
>   }
>   shared const int[] x;
>   pragma(msg, typeof(fun(x)));
> 
> > const(shared(int)[])    !!!
> 
> `T` should be typeof(x) but with shared peeled away: const(int[])

It is typeof(x) but with shared peeled away (from the head of the type).

typeof(x) is: shared(const(E[])) where E is shared(const(int)).
Peel shared away from typeof(x): const(E[]).
Expand E: const(shared(const(int))[]).
Simplify: const(shared(int)[]).

(In reply to Manu from comment #5)
> In my example above, it's weird that `shared` surrounds `int`, but `const`
> surrounds `int[]`... why are they applied at different levels?

`shared` is in the signature, `const` isn't.

If you change fun's parameter to `shared(const(T)) a`, the return type becomes
`shared(const(int))[]` as expected.

--


More information about the Digitalmars-d-bugs mailing list