Bug 19120 – Cannot slice a struct with a tuple alias this

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-07-27T09:01:58Z
Last change time
2024-12-13T18:59:57Z
Keywords
pull
Assigned to
No Owner
Creator
Yuxuan Shui
Moved to GitHub: dmd#17872 →

Comments

Comment #0 by yshuiv7 — 2018-07-27T09:01:58Z
Right now if a struct has a tuple as its alias this, we could index it at compile time, but not slicing it. struct A(T...) { alias S = T; alias S this; } alias X = A!(int, double); alias Y = X[0]; // Fine alias Z = X[0..$]; // Not fine? https://godbolt.org/g/phwQFo
Comment #1 by yshuiv7 — 2018-07-27T10:02:19Z
I just came into realization that it is not possible to index a struct with alias this tuple. This seems to be quite inconvenient.
Comment #2 by yshuiv7 — 2018-07-27T10:32:21Z
Actually, we can index that struct. A revised example: import std.meta; struct A(T...) { alias S = T; alias S this; } alias X = A!(int, double); alias Y = AliasSeq!((X)[0])[0]; // Fine pragma(msg, Y); // int alias Z = AliasSeq!((X)[0..$]); // Not fine?
Comment #3 by yshuiv7 — 2019-05-23T10:25:50Z
To clarify: The problem of comment #0 is that Y is actually an array (A!(int, double)[0]). So that is not a valid example. But the problem is real, as the example in comment #2 shows. It is possible to index A!(int, double), but not slicing it. Which seems to be an arbitrary limitation.
Comment #4 by dlang-bot — 2021-05-08T16:50:44Z
@TungstenHeart created dlang/dmd pull request #12505 "fix 19120 - allow CT slicing via `alias this`" fixing this issue: - fix 19120 - allow CT slicing via `alias this` To be consistent with the fact that indexing works https://github.com/dlang/dmd/pull/12505
Comment #5 by robert.schadek — 2024-12-13T18:59:57Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17872 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB