Skip to content

Commit

Permalink
bugzilla 4296 Reduce parasitic error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Walter Bright committed Jun 9, 2010
1 parent b729847 commit adbc1e4
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ printf("%p %p type: %s to: %s\n", type->deco, t->deco, type->deco, t->deco);
//printf("%p %p %p\n", type->nextOf()->arrayOf(), type, t);
fflush(stdout);
#endif
if (t->ty != Terror)
if (t->ty != Terror && type->ty != Terror)
{
if (!t->deco)
{ /* Can happen with:
Expand Down
5 changes: 3 additions & 2 deletions src/constfold.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,9 @@ Expression *Cast(Type *type, Type *to, Expression *e1)
}
else
{
error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars());
e = new IntegerExp(loc, 0, Type::tint32);
if (type != Type::terror)
error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars());
e = new ErrorExp();
}
return e;
}
Expand Down
112 changes: 74 additions & 38 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,18 +1105,24 @@ char *Expression::toChars()

void Expression::error(const char *format, ...)
{
va_list ap;
va_start(ap, format);
::verror(loc, format, ap);
va_end( ap );
if (type != Type::terror)
{
va_list ap;
va_start(ap, format);
::verror(loc, format, ap);
va_end( ap );
}
}

void Expression::warning(const char *format, ...)
{
va_list ap;
va_start(ap, format);
::vwarning(loc, format, ap);
va_end( ap );
if (type != Type::terror)
{
va_list ap;
va_start(ap, format);
::vwarning(loc, format, ap);
va_end( ap );
}
}

void Expression::rvalue()
Expand Down Expand Up @@ -1246,7 +1252,7 @@ void Expression::checkEscapeRef()

void Expression::checkScalar()
{
if (!type->isscalar())
if (!type->isscalar() && type->toBasetype() != Type::terror)
error("'%s' is not a scalar, it is a %s", toChars(), type->toChars());
rvalue();
}
Expand All @@ -1260,7 +1266,8 @@ void Expression::checkNoBool()
Expression *Expression::checkIntegral()
{
if (!type->isintegral())
{ error("'%s' is not of integral type, it is a %s", toChars(), type->toChars());
{ if (type->toBasetype() != Type::terror)
error("'%s' is not of integral type, it is a %s", toChars(), type->toChars());
return new ErrorExp();
}
rvalue();
Expand All @@ -1270,7 +1277,8 @@ Expression *Expression::checkIntegral()
Expression *Expression::checkArithmetic()
{
if (!type->isintegral() && !type->isfloating())
{ error("'%s' is not of arithmetic type, it is a %s", toChars(), type->toChars());
{ if (type->toBasetype() != Type::terror)
error("'%s' is not of arithmetic type, it is a %s", toChars(), type->toChars());
return new ErrorExp();
}
rvalue();
Expand Down Expand Up @@ -1400,8 +1408,8 @@ Expression *Expression::checkToBoolean(Scope *sc)
}

if (!type->checkBoolean())
{
error("expression %s of type %s does not have a boolean value", toChars(), type->toChars());
{ if (type->toBasetype() != Type::terror)
error("expression %s of type %s does not have a boolean value", toChars(), type->toChars());
return new ErrorExp();
}
return this;
Expand Down Expand Up @@ -1830,6 +1838,11 @@ ErrorExp::ErrorExp()
op = TOKerror;
}

Expression *ErrorExp::toLvalue(Scope *sc, Expression *e)
{
return this;
}

void ErrorExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
buf->writestring("__error");
Expand Down Expand Up @@ -5527,9 +5540,12 @@ int BinExp::canThrow()

void BinExp::incompatibleTypes()
{
error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
e1->toChars(), Token::toChars(op), e2->toChars(),
e1->type->toChars(), e2->type->toChars());
if (e1->type->toBasetype() != Type::terror &&
e2->type->toBasetype() != Type::terror
)
error("incompatible types for ((%s) %s (%s)): '%s' and '%s'",
e1->toChars(), Token::toChars(op), e2->toChars(),
e1->type->toChars(), e2->type->toChars());
}

/********************** BinAssignExp **************************************/
Expand Down Expand Up @@ -7531,6 +7547,7 @@ Expression *PtrExp::semantic(Scope *sc)

default:
error("can only * a pointer, not a '%s'", e1->type->toChars());
case Terror:
return new ErrorExp();
}
rvalue();
Expand Down Expand Up @@ -8150,11 +8167,15 @@ Expression *SliceExp::semantic(Scope *sc)
{ lwr = lwr->semantic(sc2);
lwr = resolveProperties(sc2, lwr);
lwr = lwr->implicitCastTo(sc2, Type::tsize_t);
if (lwr->type == Type::terror)
goto Lerr;
}
if (upr)
{ upr = upr->semantic(sc2);
upr = resolveProperties(sc2, upr);
upr = upr->implicitCastTo(sc2, Type::tsize_t);
if (upr->type == Type::terror)
goto Lerr;
}

if (sc2 != sc)
Expand Down Expand Up @@ -8210,7 +8231,7 @@ Expression *SliceExp::semantic(Scope *sc)
else
{
error("string slice [%ju .. %ju] is out of bounds", i1, i2);
e = new ErrorExp();
goto Lerr;
}
return e;
}
Expand All @@ -8232,6 +8253,7 @@ Expression *SliceExp::semantic(Scope *sc)
else
s = t->toChars();
error("%s cannot be sliced with []", s);
Lerr:
e = new ErrorExp();
return e;
}
Expand Down Expand Up @@ -8414,6 +8436,8 @@ Expression *ArrayExp::semantic(Scope *sc)
{ error("%s has no value", e->toChars());
goto Lerr;
}
else if (e->type == Type::terror)
goto Lerr;
arguments->data[i] = (void *)e;
}

Expand Down Expand Up @@ -8594,9 +8618,11 @@ Expression *IndexExp::semantic(Scope *sc)
if (!e2->type)
{
error("%s has no value", e2->toChars());
return new ErrorExp();
goto Lerr;
}
e2 = resolveProperties(sc, e2);
if (e2->type == Type::terror)
goto Lerr;

if (t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Ttuple)
sc = sc->pop();
Expand Down Expand Up @@ -8682,9 +8708,13 @@ Expression *IndexExp::semantic(Scope *sc)
default:
error("%s must be an array or pointer type, not %s",
e1->toChars(), e1->type->toChars());
return new ErrorExp();
case Terror:
goto Lerr;
}
return e;

Lerr:
return new ErrorExp();
}

#if DMDV2
Expand Down Expand Up @@ -9395,7 +9425,8 @@ Expression *CatAssignExp::semantic(Scope *sc)
}
else
{
error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars());
if (tb1 != Type::terror && tb2 != Type::terror)
error("cannot append type %s to type %s", tb2->toChars(), tb1->toChars());
e = new ErrorExp();
}
return e;
Expand Down Expand Up @@ -9741,7 +9772,7 @@ Expression *PowAssignExp::semantic(Scope *sc)
e = e->semantic(sc);
return e;
}
error("%s ^^= %s is not supported", e1->type->toChars(), e2->type->toChars() );
incompatibleTypes();
return new ErrorExp();
}

Expand Down Expand Up @@ -10023,8 +10054,7 @@ Expression *CatExp::semantic(Scope *sc)
else
{
//printf("(%s) ~ (%s)\n", e1->toChars(), e2->toChars());
error("Can only concatenate arrays, not (%s ~ %s)",
e1->type->toChars(), e2->type->toChars());
incompatibleTypes();
return new ErrorExp();
}
e->type = e->type->semantic(loc, sc);
Expand Down Expand Up @@ -10333,7 +10363,7 @@ Expression *PowExp::semantic(Scope *sc)

return e;
}
error("%s ^^ %s is not supported", e1->type->toChars(), e2->type->toChars() );
incompatibleTypes();
return new ErrorExp();
}

Expand Down Expand Up @@ -10665,24 +10695,30 @@ Expression *InExp::semantic(Scope *sc)

//type = Type::tboolean;
Type *t2b = e2->type->toBasetype();
if (t2b->ty != Taarray)
switch (t2b->ty)
{
error("rvalue of in expression must be an associative array, not %s", e2->type->toChars());
return new ErrorExp();
}
else
{
TypeAArray *ta = (TypeAArray *)t2b;

// Special handling for array keys
if (!arrayTypeCompatible(e1->loc, e1->type, ta->index))
case Taarray:
{
// Convert key to type of key
e1 = e1->implicitCastTo(sc, ta->index);
TypeAArray *ta = (TypeAArray *)t2b;

#if DMDV2
// Special handling for array keys
if (!arrayTypeCompatible(e1->loc, e1->type, ta->index))
#endif
{
// Convert key to type of key
e1 = e1->implicitCastTo(sc, ta->index);
}

// Return type is pointer to value
type = ta->nextOf()->pointerTo();
break;
}

// Return type is pointer to value
type = ta->nextOf()->pointerTo();
default:
error("rvalue of in expression must be an associative array, not %s", e2->type->toChars());
case Terror:
return new ErrorExp();
}
return this;
}
Expand Down
1 change: 1 addition & 0 deletions src/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ struct ErrorExp : IntegerExp

Expression *implicitCastTo(Scope *sc, Type *t);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *toLvalue(Scope *sc, Expression *e);
};

struct RealExp : Expression
Expand Down
2 changes: 1 addition & 1 deletion src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -7689,7 +7689,7 @@ Type *TypeSlice::semantic(Loc loc, Scope *sc)
args->push(arg);
}

Type *t = new TypeTuple(args)->semantic(loc, sc);
Type *t = (new TypeTuple(args))->semantic(loc, sc);
return t;
}

Expand Down
5 changes: 4 additions & 1 deletion src/scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,10 @@ void *scope_search_fp(void *arg, const char *seed)
/* If not in the lexer's string table, it certainly isn't in the symbol table.
* Doing this first is a lot faster.
*/
StringValue *sv = Lexer::stringtable.lookup(seed, strlen(seed));
size_t len = strlen(seed);
if (!len)
return NULL;
StringValue *sv = Lexer::stringtable.lookup(seed, len);
if (!sv)
return NULL;
Identifier *id = (Identifier *)sv->ptrvalue;
Expand Down

0 comments on commit adbc1e4

Please sign in to comment.