[Issue 15730] New: invalid template merging in tuple foreach

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Feb 27 03:21:42 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15730

          Issue ID: 15730
           Summary: invalid template merging in tuple foreach
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: ketmar at ketmar.no-ip.org

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.

--


More information about the Digitalmars-d-bugs mailing list