Skip to content

Commit

Permalink
Merge pull request dlang#255 from 9rnsr/fix6331
Browse files Browse the repository at this point in the history
[CTFE] Cannot evaluate SliceExp on if condition
  • Loading branch information
WalterBright committed Jul 17, 2011
2 parents 48f90e0 + d836692 commit ea9ace3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/expression.c
Expand Up @@ -8626,6 +8626,11 @@ Expression *SliceExp::modifiableLvalue(Scope *sc, Expression *e)
return this;
}

int SliceExp::isBool(int result)
{
return e1->isBool(result);
}

void SliceExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
expToCBuffer(buf, hgs, e1, precedence[op]);
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Expand Up @@ -1101,6 +1101,7 @@ struct SliceExp : UnaExp
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *optimize(int result);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
Expand Down
12 changes: 12 additions & 0 deletions test/compilable/interpret3.d
Expand Up @@ -1914,3 +1914,15 @@ int bug4448b()
}

static assert(bug4448b()==3);

/**************************************************
6331 - evaluate SliceExp on if condition
**************************************************/

bool bug6331(string s)
{
if (s[0..1])
return true;
return false;
}
static assert(bug6331("str"));

0 comments on commit ea9ace3

Please sign in to comment.