Skip to content

Commit

Permalink
fix Issue 11727 - Repeated error message with using forward reference…
Browse files Browse the repository at this point in the history
…d enum as variable
  • Loading branch information
9rnsr committed Dec 13, 2013
1 parent 0e583e5 commit 65d3e90
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/expression.c
Expand Up @@ -2030,10 +2030,11 @@ void Expression::deprecation(const char *format, ...)
}
}

int Expression::rvalue()
int Expression::rvalue(bool allowVoid)
{
if (type && type->toBasetype()->ty == Tvoid)
{ error("expression %s is void and has no value", toChars());
if (!allowVoid && type && type->toBasetype()->ty == Tvoid)
{
error("expression %s is void and has no value", toChars());
#if 0
dump(0);
halt();
Expand Down Expand Up @@ -4931,7 +4932,7 @@ Expression *TypeExp::semantic(Scope *sc)
return e;
}

int TypeExp::rvalue()
int TypeExp::rvalue(bool allowVoid)
{
error("type %s has no value", toChars());
return 0;
Expand Down Expand Up @@ -5095,7 +5096,7 @@ void TemplateExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
buf->writestring(td->toChars());
}

int TemplateExp::rvalue()
int TemplateExp::rvalue(bool allowVoid)
{
error("template %s has no value", toChars());
return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/expression.h
Expand Up @@ -136,7 +136,7 @@ class Expression : public RootObject
void error(const char *format, ...);
void warning(const char *format, ...);
void deprecation(const char *format, ...);
virtual int rvalue();
virtual int rvalue(bool allowVoid = false);

static Expression *combine(Expression *e1, Expression *e2);
static Expressions *arraySyntaxCopy(Expressions *exps);
Expand Down Expand Up @@ -589,7 +589,7 @@ class TypeExp : public Expression
TypeExp(Loc loc, Type *type);
Expression *syntaxCopy();
Expression *semantic(Scope *sc);
int rvalue();
int rvalue(bool allowVoid = false);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expression *optimize(int result, bool keepLvalue = false);
elem *toElem(IRState *irs);
Expand All @@ -614,7 +614,7 @@ class TemplateExp : public Expression
FuncDeclaration *fd;

TemplateExp(Loc loc, TemplateDeclaration *td, FuncDeclaration *fd = NULL);
int rvalue();
int rvalue(bool allowVoid = false);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expand Down
2 changes: 2 additions & 0 deletions src/statement.c
Expand Up @@ -3726,6 +3726,8 @@ Statement *ReturnStatement::semantic(Scope *sc)
exp = exp->inferType(fld->treq->nextOf()->nextOf());
exp = exp->semantic(sc);
exp = resolveProperties(sc, exp);
if (!exp->rvalue(true)) // don't make error for void expression
exp = new ErrorExp();
if (exp->op == TOKcall)
exp = valueNoDtor(exp);

Expand Down
39 changes: 39 additions & 0 deletions test/fail_compilation/diag11727.d
@@ -0,0 +1,39 @@
/*
TEST_OUTPUT:
---
fail_compilation/diag11727.d(10): Error: type n has no value
---
*/
auto returnEnum()
{
enum n;
return n;
}
void main()
{
assert(returnEnum() == 0);
}

/*
TEST_OUTPUT:
---
fail_compilation/diag11727.d(26): Error: type void has no value
---
*/
auto returnVoid()
{
alias v = void;
return v;
}

/*
TEST_OUTPUT:
---
fail_compilation/diag11727.d(38): Error: template t() has no value
---
*/
auto returnTemplate()
{
template t() {}
return t;
}

0 comments on commit 65d3e90

Please sign in to comment.