Skip to content

Commit

Permalink
Merge pull request #3818 from 9rnsr/fix13208
Browse files Browse the repository at this point in the history
[REG2.065] Issue 13208 - [ICE](e2ir.c 2077) with array operation
  • Loading branch information
yebblies authored and 9rnsr committed Jul 28, 2014
1 parent 1b244ba commit 043a2e3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/expression.c
Expand Up @@ -1133,6 +1133,18 @@ bool arrayExpressionToCommonType(Scope *sc, Expressions *exps, Type **pt)
t0 = Type::terror;
continue;
}
if (e->op == TOKtype)
{
e->rvalue();
t0 = Type::terror;
continue;
}
if (isNonAssignmentArrayOp(e))
{
e->error("array operation %s without assignment not implemented", e->toChars());
t0 = Type::terror;
continue;
}

e = e->isLvalue() ? callCpCtor(sc, e) : valueNoDtor(e);

Expand Down Expand Up @@ -1230,6 +1242,12 @@ bool preFunctionParameters(Loc loc, Scope *sc, Expressions *exps)
arg = new ErrorExp();
err = true;
}
if (isNonAssignmentArrayOp(arg))
{
arg->error("array operation %s without assignment not implemented", arg->toChars());
arg = new ErrorExp();
err = true;
}
(*exps)[i] = arg;
}
}
Expand Down Expand Up @@ -1383,7 +1401,8 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
size_t nparams = Parameter::dim(tf->parameters);

if (nargs > nparams && tf->varargs == 0)
{ error(loc, "expected %llu arguments, not %llu for non-variadic function type %s", (ulonglong)nparams, (ulonglong)nargs, tf->toChars());
{
error(loc, "expected %llu arguments, not %llu for non-variadic function type %s", (ulonglong)nparams, (ulonglong)nargs, tf->toChars());
return Type::terror;
}

Expand Down Expand Up @@ -1606,20 +1625,6 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
{
Expression *arg = (*arguments)[i];
assert(arg);

if (arg->op == TOKtype)
{
arg->error("cannot pass type %s as function argument", arg->toChars());
arg = new ErrorExp();
goto L3;
}
if (isNonAssignmentArrayOp(arg))
{
arg->error("array operation %s without assignment not implemented", arg->toChars());
arg = new ErrorExp();
goto L3;
}

if (i < nparams)
{
Parameter *p = Parameter::getNth(tf->parameters, i);
Expand Down Expand Up @@ -8171,8 +8176,11 @@ Expression *CallExp::semantic(Scope *sc)

if (e1->op == TOKfunction)
{
arrayExpressionSemantic(arguments, sc);
preFunctionParameters(loc, sc, arguments);
if (arrayExpressionSemantic(arguments, sc) ||
preFunctionParameters(loc, sc, arguments))
{
return new ErrorExp();
}

// Run e1 semantic even if arguments have any errors
FuncExp *fe = (FuncExp *)e1;
Expand Down Expand Up @@ -8491,9 +8499,6 @@ Expression *CallExp::semantic(Scope *sc)
}
else if (e1->op == TOKtype && t1->isscalar())
{
if (arrayExpressionSemantic(arguments, sc))
return new ErrorExp();
preFunctionParameters(loc, sc, arguments);
Expression *e;
if (!arguments || arguments->dim == 0)
{
Expand Down
25 changes: 25 additions & 0 deletions test/fail_compilation/ice12179.d
Expand Up @@ -56,3 +56,28 @@ float[] f12769(float[] a)
else
return (-a[])[0..4];
}

/*
TEST_OUTPUT:
---
fail_compilation/ice12179.d(74): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(76): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(77): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(80): Error: array operation a[] - a[] without assignment not implemented
fail_compilation/ice12179.d(82): Error: array operation a[] - a[] without assignment not implemented
---
*/
void test13208()
{
int[] a;

auto arr = [a[] - a[]][0];

auto aa1 = [1 : a[] - a[]];
auto aa2 = [a[] - a[] : 1];

struct S { int[] a; }
auto s = S(a[] - a[]);

auto n = int(a[] - a[]);
}

0 comments on commit 043a2e3

Please sign in to comment.