Skip to content

Commit

Permalink
Merge pull request #3502 from 9rnsr/fix12651
Browse files Browse the repository at this point in the history
Issue 12651 - TemplateArgsOf accepts nonsensical arguments
  • Loading branch information
WalterBright committed Apr 27, 2014
2 parents b65f13e + 1e78567 commit 68aa8cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -5486,10 +5486,10 @@ MATCH TemplateTupleParameter::matchArg(Loc loc, Scope *sc, Objects *tiargs,
assert(i + 1 == dedtypes->dim); // must be the last one
Tuple *ovar;

if ((*dedtypes)[i] && isTuple((*dedtypes)[i]))
if (Tuple *u = isTuple((*dedtypes)[i]))
{
// It has already been deduced
ovar = isTuple((*dedtypes)[i]);
ovar = u;
}
else if (i + 1 == tiargs->dim && isTuple((*tiargs)[i]))
ovar = isTuple((*tiargs)[i]);
Expand All @@ -5516,6 +5516,14 @@ MATCH TemplateTupleParameter::matchArg(Scope *sc, RootObject *oarg,
Tuple *ovar = isTuple(oarg);
if (!ovar)
return MATCHnomatch;
if ((*dedtypes)[i])
{
Tuple *tup = isTuple((*dedtypes)[i]);
if (!tup)
return MATCHnomatch;
if (!match(tup, ovar))
return MATCHnomatch;
}
(*dedtypes)[i] = ovar;

if (psparam)
Expand Down
9 changes: 9 additions & 0 deletions test/runnable/template9.d
Original file line number Diff line number Diff line change
Expand Up @@ -3373,6 +3373,15 @@ void test12376()
enum x = __traits(compiles, encode12376!2(x));
}

/******************************************/
// 12651

alias TemplateArgsOf12651(alias T : Base!Args, alias Base, Args...) = Args;

struct S12651(T) { }

static assert(!__traits(compiles, TemplateArgsOf12651!(S12651!int, S, float)));

/******************************************/

int main()
Expand Down

0 comments on commit 68aa8cc

Please sign in to comment.