Skip to content

Commit

Permalink
Merge pull request #4426 from 9rnsr/fix14210
Browse files Browse the repository at this point in the history
Issue 14210 - invalid merging of template instances
  • Loading branch information
WalterBright committed Feb 22, 2015
2 parents e5fdbf0 + 43b3f1e commit 00cbcb3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,11 +1768,15 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(
for (size_t i = 0; i < dedtypes->dim; i++)
{
Type *at = isType((*dedtypes)[i]);
if (at && at->ty == Tnone)
if (at)
{
TypeDeduced *xt = (TypeDeduced *)at;
(*dedtypes)[i] = xt->tded; // 'unbox'
delete xt;
if (at->ty == Tnone)
{
TypeDeduced *xt = (TypeDeduced *)at;
at = xt->tded; // 'unbox'
delete xt;
}
(*dedtypes)[i] = at->merge2();
}
}
for (size_t i = ntargs; i < dedargs->dim; i++)
Expand Down
21 changes: 21 additions & 0 deletions test/runnable/functype.d
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,26 @@ void test8579()
static assert(typeof(fn4).stringof == "int function(int i, double j = " ~ (1.0).stringof ~ ")");
}

/***************************************************/
// 14210

string foo14210a(DT)(string name, DT dg)
{
return name ~ " :: " ~ typeof(dg).stringof;
}
string foo14210b(DT)(string name, DT dg)
{
return name ~ " :: " ~ typeof(dg).stringof;
}
void test14210()
{
assert(foo14210a("1", (int a) => a+0) == "1 :: int function(int) pure nothrow @nogc @safe");
assert(foo14210a("2", (int a=40) => a+2) == "2 :: int function(int) pure nothrow @nogc @safe");

assert(foo14210b("2", (int a=40) => a+2) == "2 :: int function(int) pure nothrow @nogc @safe");
assert(foo14210b("1", (int a) => a+0) == "1 :: int function(int) pure nothrow @nogc @safe");
}

/***************************************************/
// 10734

Expand Down Expand Up @@ -288,6 +308,7 @@ int main()
test3646();
test3866();
test8579();
test14210();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 00cbcb3

Please sign in to comment.