Bug 22421 – static foreach introduces semantic difference between indexing and iteration variable

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-10-18T18:57:48Z
Last change time
2021-11-04T15:25:50Z
Keywords
pull
Assigned to
No Owner
Creator
Andrei Alexandrescu

Comments

Comment #0 by andrei — 2021-10-18T18:57:48Z
Consider the code below. Both versions should work the same, but the second causes an assertion error. alias AliasSeq(T...) = T; version(works) template staticMap(alias fun, args...) { alias staticMap = AliasSeq!(); static foreach(i; 0 .. args.length) staticMap = AliasSeq!(staticMap, fun!(args[i])); } else // BUG below template staticMap(alias fun, args...) { alias staticMap = AliasSeq!(); static foreach(arg; args) staticMap = AliasSeq!(staticMap, fun!arg); } template id(alias what) { enum id = __traits(identifier, what); } enum A { a } static assert(staticMap!(id, A.a) == AliasSeq!("a"));
Comment #1 by destructionator — 2021-10-18T19:33:33Z
i wanna follow the thread i suspect this has to do with an assignment to a temporary in the loop forcing eval of the ctfe thing, turning it from an alias symbol into a value. but using the `alias` keyword in the static foreach still does it which makes me not sure.
Comment #2 by dlang-bot — 2021-11-01T03:58:09Z
@BorisCarvajal created dlang/dmd pull request #13252 "Fix Issue 22421 - static foreach introduces semantic difference between indexing and iteration variable" fixing this issue: - Fix Issue 22421 - static foreach introduces semantic difference between indexing and iteration variable https://github.com/dlang/dmd/pull/13252
Comment #3 by dlang-bot — 2021-11-04T15:25:50Z
dlang/dmd pull request #13252 "Fix Issue 22421 - static foreach introduces semantic difference between indexing and iteration variable" was merged into master: - 888beec5512e676a59c7c8ef3bee532e9a519bc1 by Boris Carvajal: Fix Issue 22421 - static foreach introduces semantic difference between indexing and iteration variable https://github.com/dlang/dmd/pull/13252