Bug 15730 – invalid template merging in tuple foreach
Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-02-27T11:21:42Z
Last change time
2022-03-23T17:30:26Z
Assigned to
No Owner
Creator
Ketmar Dark
Comments
Comment #0 by ketmar — 2016-02-27T11:21:42Z
the following code fails with "Error: function pointer arg () is not callable using argument types (Object)"
void selector(A...) (Object o, scope A args) {
import std.traits : arity;
foreach (immutable aidx, arg; args) {
static if (arity!arg == 0) arg(); else arg(o);
}
}
void main () {
selector(new Object,
(Object o) {},
() {}
);
}
but if one will change static if line to this:
static if (arity!(args[aidx]) == 0) arg(); else arg(o);
everything is working right.
the bug is that frontend doesn't differentiate between template instantiations in unrolled `foreach` loop, and merges all `arity` instantiations to the first one, which returns `1`.
compiler should either reject such code, or stop merging templates if there is `foreach` arg used to make an instance.
Comment #1 by moonlightsentinel — 2022-03-23T17:30:26Z