Skip to content

Commit

Permalink
Merge pull request #871 from 9rnsr/fix7871
Browse files Browse the repository at this point in the history
Issue 7871 - RangeViolation with findSplitBefore
  • Loading branch information
WalterBright committed Apr 9, 2012
2 parents d06e17d + 88bf66c commit 6888809
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/expression.c
Expand Up @@ -8970,7 +8970,9 @@ Expression *SliceExp::syntaxCopy()
if (this->upr)
upr = this->upr->syntaxCopy();

return new SliceExp(loc, e1->syntaxCopy(), lwr, upr);
SliceExp *se = new SliceExp(loc, e1->syntaxCopy(), lwr, upr);
se->lengthVar = this->lengthVar; // bug7871
return se;
}

Expression *SliceExp::semantic(Scope *sc)
Expand Down Expand Up @@ -9315,7 +9317,9 @@ ArrayExp::ArrayExp(Loc loc, Expression *e1, Expressions *args)

Expression *ArrayExp::syntaxCopy()
{
return new ArrayExp(loc, e1->syntaxCopy(), arraySyntaxCopy(arguments));
ArrayExp *ae = new ArrayExp(loc, e1->syntaxCopy(), arraySyntaxCopy(arguments));
ae->lengthVar = this->lengthVar; // bug7871
return ae;
}

Expression *ArrayExp::semantic(Scope *sc)
Expand Down Expand Up @@ -9482,6 +9486,13 @@ IndexExp::IndexExp(Loc loc, Expression *e1, Expression *e2)
modifiable = 0; // assume it is an rvalue
}

Expression *IndexExp::syntaxCopy()
{
IndexExp *ie = new IndexExp(loc, e1->syntaxCopy(), e2->syntaxCopy());
ie->lengthVar = this->lengthVar; // bug7871
return ie;
}

Expression *IndexExp::semantic(Scope *sc)
{ Expression *e;
Type *t1;
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Expand Up @@ -1196,6 +1196,7 @@ struct IndexExp : BinExp
int modifiable;

IndexExp(Loc loc, Expression *e1, Expression *e2);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expand Down
22 changes: 22 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -4945,6 +4945,27 @@ struct A7823 {

void test7823(A7823 a = A7823.b) { }

/***************************************************/
// 7871

struct Tuple7871
{
string field;
alias field this;
}

//auto findSplitBefore(R1)(R1 haystack)
auto findSplitBefore7871(string haystack)
{
return Tuple7871(haystack);
}

void test7871()
{
string line = `<bookmark href="https://stuff">`;
auto a = findSplitBefore7871(line[0 .. $])[0];
}

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

int main()
Expand Down Expand Up @@ -5173,6 +5194,7 @@ int main()
test7682();
test7735();
test7823();
test7871();

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

0 comments on commit 6888809

Please sign in to comment.