Skip to content

Commit

Permalink
Issue 4269 - Regression(2.031): invalid type accepted if evaluated wh…
Browse files Browse the repository at this point in the history
…ile errors are gagged
  • Loading branch information
WalterBright committed Feb 7, 2012
1 parent 7cd2d8b commit 75ccf8c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct AggregateDeclaration : ScopeDsymbol
// 1: size is correct
// 2: cannot determine size; fwd referenced
Dsymbol *deferred; // any deferred semantic2() or semantic3() symbol
int isdeprecated; // !=0 if deprecated
bool isdeprecated; // !=0 if deprecated

#if DMDV2
int isnested; // !=0 if is nested
Expand Down
34 changes: 25 additions & 9 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ void ClassDeclaration::semantic(Scope *sc)
methods.setDim(0);
#endif

int errors = global.gaggedErrors;

if (sc->stc & STCdeprecated)
{
isdeprecated = 1;
isdeprecated = true;
}

if (sc->linkage == LINKcpp)
Expand All @@ -303,9 +305,7 @@ void ClassDeclaration::semantic(Scope *sc)
// Expand any tuples in baseclasses[]
for (size_t i = 0; i < baseclasses->dim; )
{ BaseClass *b = baseclasses->tdata()[i];
//printf("test1 %s %s\n", toChars(), b->type->toChars());
b->type = b->type->semantic(loc, sc);
//printf("test2\n");
Type *tb = b->type->toBasetype();

if (tb->ty == Ttuple)
Expand Down Expand Up @@ -345,7 +345,7 @@ void ClassDeclaration::semantic(Scope *sc)
if (!isDeprecated())
{
// Deriving from deprecated class makes this one deprecated too
isdeprecated = 1;
isdeprecated = true;

tc->checkDeprecated(loc, sc);
}
Expand Down Expand Up @@ -418,7 +418,7 @@ void ClassDeclaration::semantic(Scope *sc)
if (!isDeprecated())
{
// Deriving from deprecated class makes this one deprecated too
isdeprecated = 1;
isdeprecated = true;

tc->checkDeprecated(loc, sc);
}
Expand Down Expand Up @@ -653,9 +653,17 @@ void ClassDeclaration::semantic(Scope *sc)
s->semantic(sc);
}

if (sizeok == 2)
{ // semantic() failed because of forward references.
if (global.gag && global.gaggedErrors != errors)
{ // The type is no good, yet the error messages were gagged.
type = Type::terror;
}

if (sizeok == 2) // failed due to forward references
{ // semantic() failed due to forward references
// Unwind what we did, and defer it for later
sizeok = 0;
symtab = NULL;

fields.setDim(0);
structsize = 0;
alignsize = 0;
Expand Down Expand Up @@ -764,7 +772,7 @@ void ClassDeclaration::semantic(Scope *sc)
#endif
//printf("-ClassDeclaration::semantic(%s), type = %p\n", toChars(), type);

if (deferred)
if (deferred && !global.gag)
{
deferred->semantic2(sc);
deferred->semantic3(sc);
Expand Down Expand Up @@ -1221,9 +1229,11 @@ void InterfaceDeclaration::semantic(Scope *sc)
scope = NULL;
}

int errors = global.gaggedErrors;

if (sc->stc & STCdeprecated)
{
isdeprecated = 1;
isdeprecated = true;
}

// Expand any tuples in baseclasses[]
Expand Down Expand Up @@ -1374,6 +1384,12 @@ void InterfaceDeclaration::semantic(Scope *sc)
Dsymbol *s = members->tdata()[i];
s->semantic(sc);
}

if (global.gag && global.gaggedErrors != errors)
{ // The type is no good, yet the error messages were gagged.
type = Type::terror;
}

inuse--;
//members->print();
sc->pop();
Expand Down
14 changes: 11 additions & 3 deletions src/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
hasUnions = 0;
sizeok = 0; // size not determined yet
deferred = NULL;
isdeprecated = 0;
isdeprecated = false;
inv = NULL;
aggNew = NULL;
aggDelete = NULL;
Expand Down Expand Up @@ -358,6 +358,8 @@ void StructDeclaration::semantic(Scope *sc)
scope = NULL;
}

int errors = global.gaggedErrors;

unsigned dprogress_save = Module::dprogress;

parent = sc->parent;
Expand All @@ -371,7 +373,7 @@ void StructDeclaration::semantic(Scope *sc)
protection = sc->protection;
storage_class |= sc->stc;
if (sc->stc & STCdeprecated)
isdeprecated = 1;
isdeprecated = true;
assert(!isAnonymous());
if (sc->stc & STCabstract)
error("structs, unions cannot be abstract");
Expand Down Expand Up @@ -609,7 +611,13 @@ void StructDeclaration::semantic(Scope *sc)
semantic2(sc);
semantic3(sc);
}
if (deferred)

if (global.gag && global.gaggedErrors != errors)
{ // The type is no good, yet the error messages were gagged.
type = Type::terror;
}

if (deferred && !global.gag)
{
deferred->semantic2(sc);
deferred->semantic3(sc);
Expand Down
30 changes: 30 additions & 0 deletions src/toobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ void ClassDeclaration::toObjFile(int multiobj)

//printf("ClassDeclaration::toObjFile('%s')\n", toChars());

if (type->ty == Terror)
{ error("had semantic errors when compiling");
return;
}

if (!members)
return;

Expand Down Expand Up @@ -918,6 +923,11 @@ void InterfaceDeclaration::toObjFile(int multiobj)

//printf("InterfaceDeclaration::toObjFile('%s')\n", toChars());

if (type->ty == Terror)
{ error("had semantic errors when compiling");
return;
}

if (!members)
return;

Expand Down Expand Up @@ -1083,6 +1093,11 @@ void StructDeclaration::toObjFile(int multiobj)
{
//printf("StructDeclaration::toObjFile('%s')\n", toChars());

if (type->ty == Terror)
{ error("had semantic errors when compiling");
return;
}

if (multiobj && !hasStaticCtorOrDtor())
{ obj_append(this);
return;
Expand Down Expand Up @@ -1169,6 +1184,11 @@ void VarDeclaration::toObjFile(int multiobj)
//printf("VarDeclaration::toObjFile(%p '%s' type=%s) protection %d\n", this, toChars(), type->toChars(), protection);
//printf("\talign = %d\n", type->alignsize());

if (type->ty == Terror)
{ error("had semantic errors when compiling");
return;
}

if (aliassym)
{ toAlias()->toObjFile(0);
return;
Expand Down Expand Up @@ -1299,6 +1319,11 @@ void TypedefDeclaration::toObjFile(int multiobj)
{
//printf("TypedefDeclaration::toObjFile('%s')\n", toChars());

if (type->ty == Terror)
{ error("had semantic errors when compiling");
return;
}

if (global.params.symdebug)
toDebug();

Expand Down Expand Up @@ -1334,6 +1359,11 @@ void EnumDeclaration::toObjFile(int multiobj)
{
//printf("EnumDeclaration::toObjFile('%s')\n", toChars());

if (type->ty == Terror)
{ error("had semantic errors when compiling");
return;
}

#if DMDV2
if (isAnonymous())
return;
Expand Down
9 changes: 6 additions & 3 deletions test/fail_compilation/fail4269a.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
static if(is(typeof(X5.init))) {}
typedef Y X5;
enum bool WWW = is(typeof(A.x));

interface A {
B blah;
void foo(B b){}
}

void main() {}
8 changes: 5 additions & 3 deletions test/fail_compilation/fail4269b.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
enum bool WWW = is(typeof(A.x));

static if(is(typeof(X16))) {}
alias X16 X16;
struct A {
B blah;
void foo(B b){}
}

void main() {}
9 changes: 5 additions & 4 deletions test/fail_compilation/fail4269c.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
enum bool WWW = is(typeof(A.x));

int[2] d;
static if(is(typeof(Xg.init))) {}
alias d[1] Xg;
class A {
B blah;
void foo(B b){}
}

void main() {}

4 comments on commit 75ccf8c

@braddr
Copy link
Member

@braddr braddr commented on 75ccf8c Feb 7, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you haven't noticed yet, this commit looks to have broken every platform in one of the dmd tests:

../src/dmd -m32 -Irunnable -d -odtest_results/runnable -oftest_results/runnable/circular_0 runnable/circular.d runnable/imports/circularA.d
runnable/circular.d(11): Error: typedef imports.circularA.A.Tclass circular definition
runnable/circular.d(11): Error: typedef imports.circularA.A.Tclass circular definition
runnable/imports/circularA.d(5): Error: class imports.circularA.A is forward referenced when looking for 'bclass'
runnable/circular.d(14): Error: typedef imports.circularA.A.Tstruct circular definition
runnable/circular.d(14): Error: typedef imports.circularA.A.Tstruct circular definition

@WalterBright
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Will fix.

@yebblies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaced three test cases I introduced... was this intentional?

@WalterBright
Copy link
Member Author

@WalterBright WalterBright commented on 75ccf8c Feb 10, 2012 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.