Skip to content

Commit

Permalink
Merge pull request #3969 from quickfur/ice_emptytuple
Browse files Browse the repository at this point in the history
Fix issue 13434: segfault on indexing array with empty tuple
  • Loading branch information
9rnsr committed Sep 9, 2014
2 parents 3cf215f + 60f305b commit 930f0bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/expression.c
Expand Up @@ -10336,8 +10336,11 @@ Expression *IndexExp::semantic(Scope *sc)
if (t1->ty == Ttuple) sc = sc->endCTFE();
if (e2->type == Type::terror)
return new ErrorExp();
if (e2->type->ty == Ttuple && ((TupleExp *)e2)->exps->dim == 1) // bug 4444 fix
if (e2->type->ty == Ttuple && ((TupleExp *)e2)->exps &&
((TupleExp *)e2)->exps->dim == 1) // bug 4444 fix
{
e2 = (*((TupleExp *)e2)->exps)[0];
}

if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple)
sc = sc->pop();
Expand Down
14 changes: 14 additions & 0 deletions test/fail_compilation/fail13434_m32.d
@@ -0,0 +1,14 @@
// REQUIRED_ARGS: -m32
/*
TEST_OUTPUT:
---
fail_compilation/fail13434_m32.d(13): Error: cannot implicitly convert expression (()) of type () to uint
---
*/

alias tuple(A...) = A;
void main()
{
float[] arr;
arr[tuple!()] = 0;
}
14 changes: 14 additions & 0 deletions test/fail_compilation/fail13434_m64.d
@@ -0,0 +1,14 @@
// REQUIRED_ARGS: -m64
/*
TEST_OUTPUT:
---
fail_compilation/fail13434_m64.d(13): Error: cannot implicitly convert expression (()) of type () to ulong
---
*/

alias tuple(A...) = A;
void main()
{
float[] arr;
arr[tuple!()] = 0;
}

0 comments on commit 930f0bd

Please sign in to comment.