April 16, 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`.
April 16, 2020
On 4/16/20 11:21 AM, Timon Gehr wrote:
> 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; }

So you are suggesting a change to current behavior?

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

pragma(msg, is(S == immutable)); // true
pragma(msg, is(T == immutable)); // false

> 
> I think those should be equivalent declarations.

It makes sense.

But in practice, I'm sure people make an assumption based on whether something is immutable and don't check whether an struct has all immutable members, even though semantically the two are equivalent.

We would need something in std.traits that does what is needed.

-Steve
1 2
Next ›   Last »