[Issue 14210] New: invalid merging of template instances

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Feb 20 09:53:27 PST 2015


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

          Issue ID: 14210
           Summary: invalid merging of template instances
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: ketmar at ketmar.no-ip.org

compiler erroneously merges templates with different delegate types. let's run
the following code:

=== test.d ===
void test(DT) (string name, DT dg) {
  import std.stdio;
  writeln(":: ", name);
  writeln(typeof(dg).stringof);
}

void main () {
  test("001", (int a=40) => a+2);
  test("000", (int a) => a+0);
}
===

output:
:: 001
int function(int a = 40) pure nothrow @nogc @safe
:: 000
int function(int a = 40) pure nothrow @nogc @safe

now let's change `main` to:
===
void main () {
  test("000", (int a) => a+0);
  test("001", (int a=40) => a+2);
}
===

output:
:: 000
int function(int a) pure nothrow @nogc @safe
:: 001
int function(int a) pure nothrow @nogc @safe


both results are obviously wrong, 'cause compiler should not merge two
instantiations. yet compiler checks for merge possibility by checking mangled
names, and both types mangles to the same string.

this breaks automatic CTFE wrapping of functions for some scripting engines,
and possibly many more cases.

--


More information about the Digitalmars-d-bugs mailing list