Skip to content

Commit

Permalink
fix Issue 9174 - regression(2.057) ice(cast.c) with ternary operator …
Browse files Browse the repository at this point in the history
…and alias this

Precedence 'alias this' resolving than integral promotion.
  • Loading branch information
9rnsr committed Jan 22, 2013
1 parent b426356 commit 02c0599
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/cast.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2034,9 +2034,11 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
MATCH m; MATCH m;
Expression *e1 = *pe1; Expression *e1 = *pe1;
Expression *e2 = *pe2; Expression *e2 = *pe2;
Type *t1b = e1->type->toBasetype();
Type *t2b = e2->type->toBasetype();


if (e->op != TOKquestion || if (e->op != TOKquestion ||
e1->type->toBasetype()->ty != e2->type->toBasetype()->ty) t1b->ty != t2b->ty && (t1b->isTypeBasic() && t2b->isTypeBasic()))
{ {
e1 = e1->integralPromotions(sc); e1 = e1->integralPromotions(sc);
e2 = e2->integralPromotions(sc); e2 = e2->integralPromotions(sc);
Expand All @@ -2055,8 +2057,8 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
assert(t2); assert(t2);


Lagain: Lagain:
Type *t1b = t1->toBasetype(); t1b = t1->toBasetype();
Type *t2b = t2->toBasetype(); t2b = t2->toBasetype();


TY ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty]; TY ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty];
if (ty != Terror) if (ty != Terror)
Expand Down Expand Up @@ -2477,6 +2479,13 @@ int typeMerge(Scope *sc, Expression *e, Type **pt, Expression **pe1, Expression
} }
else if (t1->isintegral() && t2->isintegral()) else if (t1->isintegral() && t2->isintegral())
{ {
if (t1->ty != t2->ty)
{
e1 = e1->integralPromotions(sc);
e2 = e2->integralPromotions(sc);
t1 = e1->type; t1b = t1->toBasetype();
t2 = e2->type; t2b = t2->toBasetype();
}
assert(t1->ty == t2->ty); assert(t1->ty == t2->ty);
if (!t1->isImmutable() && !t2->isImmutable() && t1->isShared() != t2->isShared()) if (!t1->isImmutable() && !t2->isImmutable() && t1->isShared() != t2->isShared())
goto Lincompatible; goto Lincompatible;
Expand Down
15 changes: 15 additions & 0 deletions test/runnable/aliasthis.d
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -879,6 +879,20 @@ void test8169()
static assert(typeof(ValueUser.m_valueImpl).getValue() == 42); // #3, OK static assert(typeof(ValueUser.m_valueImpl).getValue() == 42); // #3, OK
} }


/***************************************************/
// 9174

void test9174()
{
static struct Foo
{
char x;
alias x this;
}
static assert(is(typeof(true ? 'A' : Foo()) == char));
static assert(is(typeof(true ? Foo() : 100) == int));
}

/***************************************************/ /***************************************************/
// 9177 // 9177


Expand Down Expand Up @@ -924,6 +938,7 @@ int main()
test7945(); test7945();
test7992(); test7992();
test8169(); test8169();
test9174();


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

0 comments on commit 02c0599

Please sign in to comment.