Skip to content

Commit

Permalink
Print debug/version level instead of __anonymous in error messages.
Browse files Browse the repository at this point in the history
When integer debug/version levels are used, ident is not defined,
causing Dsymbol::toChars() to print "__anonymous", which is unhelpful.
Instead, it should return the debug/version level being set as an
integer.
  • Loading branch information
H. S. Teoh committed Nov 28, 2014
1 parent b0f168b commit ffb2b73
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/version.c
Expand Up @@ -40,6 +40,18 @@ DebugSymbol::DebugSymbol(Loc loc, unsigned level)
this->loc = loc;
}

char *DebugSymbol::toChars()
{
if (ident)
return ident->toChars();
else
{
OutBuffer buf;
buf.printf("%d", level);
return buf.extractString();
}
}

Dsymbol *DebugSymbol::syntaxCopy(Dsymbol *s)
{
assert(!s);
Expand Down Expand Up @@ -117,6 +129,18 @@ VersionSymbol::VersionSymbol(Loc loc, unsigned level)
this->loc = loc;
}

char *VersionSymbol::toChars()
{
if (ident)
return ident->toChars();
else
{
OutBuffer buf;
buf.printf("%d", level);
return buf.extractString();
}
}

Dsymbol *VersionSymbol::syntaxCopy(Dsymbol *s)
{
assert(!s);
Expand Down
2 changes: 2 additions & 0 deletions src/version.h
Expand Up @@ -27,6 +27,7 @@ class DebugSymbol : public Dsymbol
DebugSymbol(Loc loc, unsigned level);
Dsymbol *syntaxCopy(Dsymbol *);

char *toChars();
int addMember(Scope *sc, ScopeDsymbol *sds, int memnum);
void semantic(Scope *sc);
const char *kind();
Expand All @@ -42,6 +43,7 @@ class VersionSymbol : public Dsymbol
VersionSymbol(Loc loc, unsigned level);
Dsymbol *syntaxCopy(Dsymbol *);

char *toChars();
int addMember(Scope *sc, ScopeDsymbol *sds, int memnum);
void semantic(Scope *sc);
const char *kind();
Expand Down
4 changes: 2 additions & 2 deletions test/fail_compilation/test13786.d
@@ -1,9 +1,9 @@
/*
TEST_OUTPUT:
---
fail_compilation/test13786.d(14): Error: debug __anonymous level declaration must be at module level
fail_compilation/test13786.d(14): Error: debug 123 level declaration must be at module level
fail_compilation/test13786.d(15): Error: debug abc declaration must be at module level
fail_compilation/test13786.d(16): Error: version __anonymous level declaration must be at module level
fail_compilation/test13786.d(16): Error: version 123 level declaration must be at module level
fail_compilation/test13786.d(17): Error: version abc declaration must be at module level
fail_compilation/test13786.d(20): Error: template instance test13786.T!() error instantiating
---
Expand Down

0 comments on commit ffb2b73

Please sign in to comment.