digitalmars.D.learn - const of AliasSeq is silently ignored
- Yuxuan Shui (6/6) Apr 08 2019 In this example:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (11/16) Apr 08 2019 I would expect that to mean a type list (int, int) that cannot be
- Alex (13/19) Apr 09 2019 kinda makes sense and making sense are two different things. It
- Paul Backus (4/10) Apr 09 2019 It works if you use the "storage class" syntax for const:
- Steven Schveighoffer (8/17) Apr 11 2019 I agree with you, please file a bug. I would have expected it to be
In this example: const(AliasSeq!(int, int)) a; pragma(msg, typeof(a)); // (int, int) This kind of make sense, since AliasSeq is not a "single" type. But silently dropping const seems bad, the compiler should probably report an error/warning in this case?
Apr 08 2019
On 04/08/2019 12:56 PM, Yuxuan Shui wrote:In this example: const(AliasSeq!(int, int)) a;I would expect that to mean a type list (int, int) that cannot be modified, meaning that it is not allowed to change it from (int, int).pragma(msg, typeof(a)); // (int, int)Makes sense to me. However, there is no syntax that allows mutating an AliasSeq. In other words, the following doesn't compile anyway: AliasSeq!(int, int) a; a ~= AliasSeq!(double); So, adding const to that construct does not add any meaning but not many people would notice it. :) Ali
Apr 08 2019
On Monday, 8 April 2019 at 19:56:50 UTC, Yuxuan Shui wrote:In this example: const(AliasSeq!(int, int)) a; pragma(msg, typeof(a)); // (int, int) This kind of make sense, since AliasSeq is not a "single" type. But silently dropping const seems bad, the compiler should probably report an error/warning in this case?kinda makes sense and making sense are two different things. It has to make sense to the compiler. While I see that you want to distribute const over the list, D is not designed to do this with anything that I know of. It could, without issue, but one must makes sure it does not contradict any other uses. If it doesn't then it could be a bonus feature. Normally though one expects const to work on it's argument and so this also suggests having a const AliasSeq. Since we can't have a const AliasSeq there may be no issue redefining it to me what you want. I agree that silently dropping things are bad. D does this sometimes and it can be a real pain.
Apr 09 2019
On Monday, 8 April 2019 at 19:56:50 UTC, Yuxuan Shui wrote:In this example: const(AliasSeq!(int, int)) a; pragma(msg, typeof(a)); // (int, int) This kind of make sense, since AliasSeq is not a "single" type. But silently dropping const seems bad, the compiler should probably report an error/warning in this case?It works if you use the "storage class" syntax for const: const AliasSeq!(int, int) a; pragma(msg, typeof(a)); // (const(int), const(int))
Apr 09 2019
On 4/8/19 3:56 PM, Yuxuan Shui wrote:In this example: const(AliasSeq!(int, int)) a; pragma(msg, typeof(a)); // (int, int) This kind of make sense, since AliasSeq is not a "single" type. But silently dropping const seems bad, the compiler should probably report an error/warning in this case?I agree with you, please file a bug. I would have expected it to be const(int), const(int). I would expect this pattern to always hold, no matter what T is. T var1; const(T) var2; static assert(is(typeof(var2) == const)); -Steve
Apr 11 2019