Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,26 @@ MATCH AssocArrayLiteralExp::implicitConvTo(Type *t)
return Expression::implicitConvTo(t);
}

MATCH CallExp::implicitConvTo(Type *t)
{
#if 0
printf("CalLExp::implicitConvTo(this=%s, type=%s, t=%s)\n",
toChars(), type->toChars(), t->toChars());
#endif

MATCH m = Expression::implicitConvTo(t);
if (m)
return m;

/* Allow the result of strongly pure functions to
* convert to immutable
*/
if (f && f->isPure() == PUREstrong)
return type->invariantOf()->implicitConvTo(t);

return MATCHnomatch;
}

MATCH AddrExp::implicitConvTo(Type *t)
{
#if 0
Expand Down
1 change: 0 additions & 1 deletion src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -6859,7 +6859,6 @@ Expression *CallExp::syntaxCopy()
Expression *CallExp::semantic(Scope *sc)
{
TypeFunction *tf;
FuncDeclaration *f;
Type *t1;
int istemp;
Objects *targsi = NULL; // initial list of template arguments
Expand Down
2 changes: 2 additions & 0 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ struct DotTypeExp : UnaExp
struct CallExp : UnaExp
{
Expressions *arguments; // function arguments
FuncDeclaration *f; // symbol to call

CallExp(Loc loc, Expression *e, Expressions *exps);
CallExp(Loc loc, Expression *e);
Expand All @@ -954,6 +955,7 @@ struct CallExp : UnaExp
Expression *toLvalue(Scope *sc, Expression *e);
int canThrow(bool mustNotThrow);
Expression *addDtorHook(Scope *sc);
MATCH implicitConvTo(Type *t);

int inlineCost(InlineCostState *ics);
Expression *doInline(InlineDoState *ids);
Expand Down
7 changes: 7 additions & 0 deletions src/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -3521,6 +3521,13 @@ Statement *ReturnStatement::semantic(Scope *sc)
}
else if (tbret->ty != Tvoid)
{
if (fd->isPureBypassingInference() == PUREstrong &&
!exp->type->implicitConvTo(tret) &&
exp->type->invariantOf()->implicitConvTo(tret))
{
exp = exp->castTo(sc, exp->type->invariantOf());
}

exp = exp->implicitCastTo(sc, tret);
if (!((TypeFunction *)fd->type)->isref)
exp = exp->optimize(WANTvalue);
Expand Down
19 changes: 19 additions & 0 deletions test/runnable/xtest46.d
Original file line number Diff line number Diff line change
Expand Up @@ -1875,6 +1875,24 @@ void test99()

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

void test5081()
{
static pure immutable(int[]) x()
{
return new int[](10);
}

static pure int[] y()
{
return new int[](10);
}

immutable a = x();
immutable b = y();
}

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

void test100()
{
string s;
Expand Down Expand Up @@ -3617,6 +3635,7 @@ int main()
test116();
test117();
test118();
test5081();

test120();

Expand Down