Help needed: immutable struct is a type modifier, and that's wrong and broken

Timon Gehr timon.gehr at gmx.ch
Thu Apr 16 15:21:58 UTC 2020


On 16.04.20 08:09, RazvanN wrote:
> On Thursday, 16 April 2020 at 06:05:12 UTC, RazvanN wrote:
>> On Thursday, 16 April 2020 at 04:28:35 UTC, Timon Gehr wrote:
>>> On 16.04.20 05:55, RazvanN wrote:
>>>>
>>>>
>>>> Additionally, I think that
>>>>
>>>> static if(is(S == immutable T, T))
>>>>
>>>> should also not pass.
>>>>
>>>> The correct form should be
>>>>
>>>> static if(is(S == immutable))
>>>>
>>>> This way you express the fact that S is an immutably defined type 
>>>> (with a storage specifier), whereas in the first case you test if S 
>>>> is an immutably declared type (with a type constructor).
>>>
>>> So the proposal is to turn `is` into an even more convoluted mess? :)
>>>
>>> Why should it even be possible to test for `immutable` on the 
>>> declaration? That seems like an implementation detail as the only 
>>> thing it achieves is that all members are marked that way.
> 
> Oh I see your point now. In the above example S and T are the same type 
> because `immutable immutable S` == `immutable S`. Right, but the fact 
> that an immutably defined struct cannot be stripped of it's qualifier 
> brings some complications here.
> 
> Anyway, the fact that T is not equal to S is definitely a bug in this 
> situation.

My point was rather that I don't see any reason why the following two 
declarations should be treated differently:

immutable struct S{ int x; }
struct S{ immutable int x; }

I think those should be equivalent declarations.

Also, I think `is(S==immutable(T),T)` and `is(S==immutable)` should 
behave the same except that the first one also declares `T`.


More information about the Digitalmars-d mailing list