Skip to content

Commit

Permalink
merge fix9383
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Mar 4, 2013
2 parents ee06e4a + 5af207f commit d2e085f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 33 deletions.
28 changes: 17 additions & 11 deletions src/cast.c
Expand Up @@ -1825,15 +1825,18 @@ Expression *SliceExp::castTo(Scope *sc, Type *t)

/****************************************
* Set type inference target
* t Target type
* flag 1: don't put an error when inference fails
* sc it is used for the semantic of t, when != NULL
* tparams template parameters should be inferred
*/

Expression *Expression::inferType(Type *t, int flag, TemplateParameters *tparams)
Expression *Expression::inferType(Type *t, int flag, Scope *sc, TemplateParameters *tparams)
{
return this;
}

Expression *ArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tparams)
Expression *ArrayLiteralExp::inferType(Type *t, int flag, Scope *sc, TemplateParameters *tparams)
{
if (t)
{
Expand All @@ -1844,7 +1847,7 @@ Expression *ArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tp
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
if (e)
{ e = e->inferType(tn, flag, tparams);
{ e = e->inferType(tn, flag, sc, tparams);
(*elements)[i] = e;
}
}
Expand All @@ -1853,7 +1856,7 @@ Expression *ArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tp
return this;
}

Expression *AssocArrayLiteralExp::inferType(Type *t, int flag, TemplateParameters *tparams)
Expression *AssocArrayLiteralExp::inferType(Type *t, int flag, Scope *sc, TemplateParameters *tparams)
{
if (t)
{
Expand All @@ -1865,14 +1868,14 @@ Expression *AssocArrayLiteralExp::inferType(Type *t, int flag, TemplateParameter
for (size_t i = 0; i < keys->dim; i++)
{ Expression *e = (*keys)[i];
if (e)
{ e = e->inferType(ti, flag, tparams);
{ e = e->inferType(ti, flag, sc, tparams);
(*keys)[i] = e;
}
}
for (size_t i = 0; i < values->dim; i++)
{ Expression *e = (*values)[i];
if (e)
{ e = e->inferType(tv, flag, tparams);
{ e = e->inferType(tv, flag, sc, tparams);
(*values)[i] = e;
}
}
Expand All @@ -1881,7 +1884,7 @@ Expression *AssocArrayLiteralExp::inferType(Type *t, int flag, TemplateParameter
return this;
}

Expression *FuncExp::inferType(Type *to, int flag, TemplateParameters *tparams)
Expression *FuncExp::inferType(Type *to, int flag, Scope *sc, TemplateParameters *tparams)
{
if (!to)
return this;
Expand Down Expand Up @@ -1939,7 +1942,10 @@ Expression *FuncExp::inferType(Type *to, int flag, TemplateParameters *tparams)
Type *tprm = p->type;
if (tprm->reliesOnTident(tparams))
goto L1;
tprm = tprm->semantic(loc, td->scope);
if (sc)
tprm = tprm->semantic(loc, sc);
if (tprm->ty == Terror)
goto L1;
tiargs->push(tprm);
u = dim; // break inner loop
}
Expand Down Expand Up @@ -1995,13 +2001,13 @@ Expression *FuncExp::inferType(Type *to, int flag, TemplateParameters *tparams)
return e;
}

Expression *CondExp::inferType(Type *t, int flag, TemplateParameters *tparams)
Expression *CondExp::inferType(Type *t, int flag, Scope *sc, TemplateParameters *tparams)
{
if (t)
{
t = t->toBasetype();
e1 = e1->inferType(t, flag, tparams);
e2 = e2->inferType(t, flag, tparams);
e1 = e1->inferType(t, flag, sc, tparams);
e2 = e2->inferType(t, flag, sc, tparams);
}
return this;
}
Expand Down
10 changes: 5 additions & 5 deletions src/expression.h
Expand Up @@ -142,7 +142,7 @@ struct Expression : Object
virtual MATCH implicitConvTo(Type *t);
virtual IntRange getIntRange();
virtual Expression *castTo(Scope *sc, Type *t);
virtual Expression *inferType(Type *t, int flag = 0, TemplateParameters *tparams = NULL);
virtual Expression *inferType(Type *t, int flag = 0, Scope *sc = NULL, TemplateParameters *tparams = NULL);
virtual void checkEscape();
virtual void checkEscapeRef();
virtual Expression *resolveLoc(Loc loc, Scope *sc);
Expand Down Expand Up @@ -452,7 +452,7 @@ struct ArrayLiteralExp : Expression
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *inferType(Type *t, int flag = 0, TemplateParameters *tparams = NULL);
Expression *inferType(Type *t, int flag = 0, Scope *sc = NULL, TemplateParameters *tparams = NULL);
dt_t **toDt(dt_t **pdt);

Expression *doInline(InlineDoState *ids);
Expand All @@ -478,7 +478,7 @@ struct AssocArrayLiteralExp : Expression
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *inferType(Type *t, int flag = 0, TemplateParameters *tparams = NULL);
Expression *inferType(Type *t, int flag = 0, Scope *sc = NULL, TemplateParameters *tparams = NULL);

Expression *doInline(InlineDoState *ids);
Expression *inlineScan(InlineScanState *iss);
Expand Down Expand Up @@ -683,7 +683,7 @@ struct FuncExp : Expression
Expression *implicitCastTo(Scope *sc, Type *t);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *inferType(Type *t, int flag = 0, TemplateParameters *tparams = NULL);
Expression *inferType(Type *t, int flag = 0, Scope *sc = NULL, TemplateParameters *tparams = NULL);
char *toChars();
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
elem *toElem(IRState *irs);
Expand Down Expand Up @@ -1656,7 +1656,7 @@ struct CondExp : BinExp
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
MATCH implicitConvTo(Type *t);
Expression *castTo(Scope *sc, Type *t);
Expression *inferType(Type *t, int flag = 0, TemplateParameters *tparams = NULL);
Expression *inferType(Type *t, int flag = 0, Scope *sc = NULL, TemplateParameters *tparams = NULL);

Expression *doInline(InlineDoState *ids);
Expression *inlineScan(InlineScanState *iss);
Expand Down
4 changes: 2 additions & 2 deletions src/template.c
Expand Up @@ -1499,7 +1499,7 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc loc, Scope *sc, Objec
if (farg->op == TOKfunction)
{ FuncExp *fe = (FuncExp *)farg;
Type *tp = prmtype;
Expression *e = fe->inferType(tp, 1, parameters);
Expression *e = fe->inferType(tp, 1, paramscope, inferparams);
if (!e)
goto Lvarargs;
farg = e;
Expand Down Expand Up @@ -1687,7 +1687,7 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Loc loc, Scope *sc, Objec
{ FuncExp *fe = (FuncExp *)arg;
Type *tp = tb->nextOf();

Expression *e = fe->inferType(tp, 1, parameters);
Expression *e = fe->inferType(tp, 1, paramscope, inferparams);
if (!e)
goto Lnomatch;
arg = e;
Expand Down
30 changes: 15 additions & 15 deletions test/compilable/extra-files/ddocYear.html
@@ -1,15 +1,15 @@
<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>ddocYear</title>
</head><body>
<h1>ddocYear</h1>
<br><br>
<dl><dt><big><a name="year"></a>int <u>year</u>;
</big></dt>
<dd>__YEAR__<br><br>

</dd>
</dl>

<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>
<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>ddocYear</title>
</head><body>
<h1>ddocYear</h1>
<br><br>
<dl><dt><big><a name="year"></a>int <u>year</u>;
</big></dt>
<dd>__YEAR__<br><br>

</dd>
</dl>

<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>
28 changes: 28 additions & 0 deletions test/runnable/funclit.d
Expand Up @@ -717,13 +717,37 @@ void test9153()
}

/***************************************************/
<<<<<<< HEAD
// 9415

void test9415()
{
int z;
typeof((int a){return z;}) dg;
dg = (int a){return z;};
=======
// 9393

template ifThrown9393a(E)
{
void ifThrown9393a(T)(scope T delegate(E) errHandler)
{
}
}
void ifThrown9393b(E, T)(scope T delegate(E) errHandler)
{
}

void foo9393(T)(void delegate(T) dg){ dg(T.init); }
void foo9393()(void delegate(int) dg){ foo9393!int(dg); }

void test9393()
{
ifThrown9393a!Exception(e => 10);
ifThrown9393b!Exception(e => 10);

foo9393((x){ assert(x == int.init); });
>>>>>>> 5af207f4650f8ca66da5f824a201c300fbd9342e
}

/***************************************************/
Expand Down Expand Up @@ -768,7 +792,11 @@ int main()
test8496();
test8575();
test9153();
<<<<<<< HEAD
test9415();
=======
test9393();
>>>>>>> 5af207f4650f8ca66da5f824a201c300fbd9342e

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

0 comments on commit d2e085f

Please sign in to comment.