diff --git a/src/template.c b/src/template.c index b485cb61add5..aa05b58b1c4e 100644 --- a/src/template.c +++ b/src/template.c @@ -2974,6 +2974,10 @@ MATCH TypeInstance::deduceType(Scope *sc, } else if (e1 && e2) { + e1 = e1->optimize(WANTvalue | WANTinterpret); + + //printf("e1 = %s, type = %s %d\n", e1->toChars(), e1->type->toChars(), e1->type->ty); + //printf("e2 = %s, type = %s %d\n", e2->toChars(), e2->type->toChars(), e2->type->ty); if (!e1->equals(e2)) { if (e2->op == TOKvar) { @@ -2983,7 +2987,13 @@ MATCH TypeInstance::deduceType(Scope *sc, j = templateIdentifierLookup(((VarExp *)e2)->var->ident, parameters); goto L1; } - goto Lnomatch; + if (!e2->implicitConvTo(e1->type)) + goto Lnomatch; + + e2 = e2->implicitCastTo(sc, e1->type); + e2 = e2->optimize(WANTvalue | WANTinterpret); + if (!e1->equals(e2)) + goto Lnomatch; } } else if (e1 && t2 && t2->ty == Tident) diff --git a/test/runnable/template9.d b/test/runnable/template9.d index 0ad447f11326..c9cfe9bfc878 100644 --- a/test/runnable/template9.d +++ b/test/runnable/template9.d @@ -1178,6 +1178,25 @@ void test7873() bar(&i); } +/**********************************/ +// 7933 + +struct Boo7933(size_t dim){int a;} +struct Baa7933(size_t dim) +{ + Boo7933!dim a; + //Boo7933!1 a; //(1) This version causes no errors +} + +auto foo7933()(Boo7933!1 b){return b;} +//auto fuu7933(Boo7933!1 b){return b;} //(2) This line neutralizes the error + +void test7933() +{ + Baa7933!1 a; //(3) This line causes the error message + auto b = foo7933(Boo7933!1(1)); +} + /**********************************/ int main() @@ -1226,6 +1245,7 @@ int main() test11b(); test7769(); test7873(); + test7933(); printf("Success\n"); return 0;