Skip to content

Commit

Permalink
fix issue 10277 - Incorrect error file and line on redeclaration of
Browse files Browse the repository at this point in the history
TypeInfo
  • Loading branch information
hpohl committed Jun 13, 2013
1 parent e5ac1cb commit 956eb92
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 69 deletions.
3 changes: 1 addition & 2 deletions src/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ class ClassDeclaration : public AggregateDeclaration
{
public:
static ClassDeclaration *object;
static ClassDeclaration *classinfo;
static ClassDeclaration *throwable;
static ClassDeclaration *exception;
static ClassDeclaration *errorException;
Expand Down Expand Up @@ -262,7 +261,7 @@ class ClassDeclaration : public AggregateDeclaration
// calling semantic() at least once, due to fill symtab
// and do addMember(). [== Semantic(Start,In,Done)]

ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses);
ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses, bool inObject = false);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expand Down
98 changes: 45 additions & 53 deletions src/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@

/********************************* ClassDeclaration ****************************/

ClassDeclaration *ClassDeclaration::classinfo;
ClassDeclaration *ClassDeclaration::object;
ClassDeclaration *ClassDeclaration::throwable;
ClassDeclaration *ClassDeclaration::exception;
ClassDeclaration *ClassDeclaration::errorException;

ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses)
ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses, bool inObject)
: AggregateDeclaration(loc, id)
{
static char msg[] = "only object.d can define this reserved class name";
Expand Down Expand Up @@ -77,155 +76,148 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
if (id->toChars()[0] == 'T')
{
if (id == Id::TypeInfo)
{ if (Type::typeinfo)
Type::typeinfo->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfo = this;
}

if (id == Id::TypeInfo_Class)
{ if (Type::typeinfoclass)
Type::typeinfoclass->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoclass = this;
}

if (id == Id::TypeInfo_Interface)
{ if (Type::typeinfointerface)
Type::typeinfointerface->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfointerface = this;
}

if (id == Id::TypeInfo_Struct)
{ if (Type::typeinfostruct)
Type::typeinfostruct->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfostruct = this;
}

if (id == Id::TypeInfo_Typedef)
{ if (Type::typeinfotypedef)
Type::typeinfotypedef->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfotypedef = this;
}

if (id == Id::TypeInfo_Pointer)
{ if (Type::typeinfopointer)
Type::typeinfopointer->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfopointer = this;
}

if (id == Id::TypeInfo_Array)
{ if (Type::typeinfoarray)
Type::typeinfoarray->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoarray = this;
}

if (id == Id::TypeInfo_StaticArray)
{ //if (Type::typeinfostaticarray)
{ //if (!inObject)
//Type::typeinfostaticarray->error("%s", msg);
Type::typeinfostaticarray = this;
}

if (id == Id::TypeInfo_AssociativeArray)
{ if (Type::typeinfoassociativearray)
Type::typeinfoassociativearray->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoassociativearray = this;
}

if (id == Id::TypeInfo_Enum)
{ if (Type::typeinfoenum)
Type::typeinfoenum->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoenum = this;
}

if (id == Id::TypeInfo_Function)
{ if (Type::typeinfofunction)
Type::typeinfofunction->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfofunction = this;
}

if (id == Id::TypeInfo_Delegate)
{ if (Type::typeinfodelegate)
Type::typeinfodelegate->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfodelegate = this;
}

if (id == Id::TypeInfo_Tuple)
{ if (Type::typeinfotypelist)
Type::typeinfotypelist->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfotypelist = this;
}

#if DMDV2
if (id == Id::TypeInfo_Const)
{ if (Type::typeinfoconst)
Type::typeinfoconst->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoconst = this;
}

if (id == Id::TypeInfo_Invariant)
{ if (Type::typeinfoinvariant)
Type::typeinfoinvariant->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoinvariant = this;
}

if (id == Id::TypeInfo_Shared)
{ if (Type::typeinfoshared)
Type::typeinfoshared->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfoshared = this;
}

if (id == Id::TypeInfo_Wild)
{ if (Type::typeinfowild)
Type::typeinfowild->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfowild = this;
}

if (id == Id::TypeInfo_Vector)
{ if (Type::typeinfovector)
Type::typeinfovector->error("%s", msg);
{ if (!inObject)
error("%s", msg);
Type::typeinfovector = this;
}
#endif
}

if (id == Id::Object)
{ if (object)
object->error("%s", msg);
{ if (!inObject)
error("%s", msg);
object = this;
}

if (id == Id::Throwable)
{ if (throwable)
throwable->error("%s", msg);
{ if (!inObject)
error("%s", msg);
throwable = this;
}

if (id == Id::Exception)
{ if (exception)
exception->error("%s", msg);
{ if (!inObject)
error("%s", msg);
exception = this;
}

if (id == Id::Error)
{ if (errorException)
errorException->error("%s", msg);
{ if (!inObject)
error("%s", msg);
errorException = this;
}

//if (id == Id::ClassInfo)
if (id == Id::TypeInfo_Class)
{ if (classinfo)
classinfo->error("%s", msg);
classinfo = this;
}

#if !MODULEINFO_IS_STRUCT
#ifdef DMDV2
if (id == Id::ModuleInfo && !Module::moduleinfo)
Module::moduleinfo = this;
#else
if (id == Id::ModuleInfo)
{ if (Module::moduleinfo)
Module::moduleinfo->error("%s", msg);
error("%s", msg);
Module::moduleinfo = this;
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -2315,7 +2315,7 @@ SymbolDeclaration::SymbolDeclaration(Loc loc, StructDeclaration *dsym)
/********************************* ClassInfoDeclaration ****************************/

ClassInfoDeclaration::ClassInfoDeclaration(ClassDeclaration *cd)
: VarDeclaration(Loc(), ClassDeclaration::classinfo->type, cd->ident, NULL)
: VarDeclaration(Loc(), Type::typeinfoclass->type, cd->ident, NULL)
{
this->cd = cd;
storage_class = STCstatic | STCgshared;
Expand Down
2 changes: 1 addition & 1 deletion src/mangle.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const char *ClassDeclaration::mangle(bool isv)
ident == Id::TypeInfo_Typedef ||
ident == Id::TypeInfo_Tuple ||
this == object ||
this == classinfo ||
this == Type::typeinfoclass ||
this == Module::moduleinfo ||
memcmp(ident->toChars(), "TypeInfo_", 9) == 0
)
Expand Down
4 changes: 2 additions & 2 deletions src/mtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -8422,8 +8422,8 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident, int f

if (ident == Id::classinfo)
{
assert(ClassDeclaration::classinfo);
Type *t = ClassDeclaration::classinfo->type;
assert(Type::typeinfoclass);
Type *t = Type::typeinfoclass->type;
if (e->op == TOKtype || e->op == TOKdottype)
{
/* For type.classinfo, we know the classinfo
Expand Down
5 changes: 4 additions & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,10 @@ Dsymbol *Parser::parseAggregate()
}

if (tok == TOKclass)
a = new ClassDeclaration(loc, id, baseclasses);
{
bool inObject = md && !md->packages && md->id == Id::object;
a = new ClassDeclaration(loc, id, baseclasses, inObject);
}
else
a = new InterfaceDeclaration(loc, id, baseclasses);
break;
Expand Down
18 changes: 9 additions & 9 deletions src/toobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,20 +485,20 @@ void ClassDeclaration::toObjFile(int multiobj)
dt_t *dt = NULL;
unsigned classinfo_size = global.params.isLP64 ? CLASSINFO_SIZE_64 : CLASSINFO_SIZE; // must be ClassInfo.size
offset = classinfo_size;
if (classinfo)
if (Type::typeinfoclass)
{
if (classinfo->structsize != classinfo_size)
if (Type::typeinfoclass->structsize != classinfo_size)
{
#ifdef DEBUG
printf("CLASSINFO_SIZE = x%x, classinfo->structsize = x%x\n", offset, classinfo->structsize);
printf("CLASSINFO_SIZE = x%x, Type::typeinfoclass->structsize = x%x\n", offset, Type::typeinfoclass->structsize);
#endif
error("mismatch between dmd and object.d or object.di found. Check installation and import paths with -v compiler switch.");
fatal();
}
}

if (classinfo)
dtxoff(&dt, classinfo->toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
if (Type::typeinfoclass)
dtxoff(&dt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
else
dtsize_t(&dt, 0); // BUG: should be an assert()
dtsize_t(&dt, 0); // monitor
Expand Down Expand Up @@ -974,8 +974,8 @@ void InterfaceDeclaration::toObjFile(int multiobj)
*/
dt_t *dt = NULL;

if (classinfo)
dtxoff(&dt, classinfo->toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
if (Type::typeinfoclass)
dtxoff(&dt, Type::typeinfoclass->toVtblSymbol(), 0, TYnptr); // vtbl for ClassInfo
else
dtsize_t(&dt, 0); // BUG: should be an assert()
dtsize_t(&dt, 0); // monitor
Expand All @@ -1000,9 +1000,9 @@ void InterfaceDeclaration::toObjFile(int multiobj)
if (vtblInterfaces->dim)
{
offset = global.params.isLP64 ? CLASSINFO_SIZE_64 : CLASSINFO_SIZE; // must be ClassInfo.size
if (classinfo)
if (Type::typeinfoclass)
{
if (classinfo->structsize != offset)
if (Type::typeinfoclass->structsize != offset)
{
error("mismatch between dmd and object.d or object.di found. Check installation and import paths with -v compiler switch.");
fatal();
Expand Down
30 changes: 30 additions & 0 deletions test/fail_compilation/fail10277.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module fail10227;

/*
TEST_OUTPUT:
---
fail_compilation/imports/fail10277.d(3): Error: class TypeInfo only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(4): Error: class TypeInfo_Class only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(5): Error: class TypeInfo_Interface only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(6): Error: class TypeInfo_Struct only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(7): Error: class TypeInfo_Typedef only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(8): Error: class TypeInfo_Pointer only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(9): Error: class TypeInfo_Array only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(10): Error: class TypeInfo_AssociativeArray only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(11): Error: class TypeInfo_Enum only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(12): Error: class TypeInfo_Function only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(13): Error: class TypeInfo_Delegate only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(14): Error: class TypeInfo_Tuple only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(15): Error: class TypeInfo_Const only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(16): Error: class TypeInfo_Invariant only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(17): Error: class TypeInfo_Shared only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(18): Error: class TypeInfo_Inout only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(19): Error: class TypeInfo_Vector only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(20): Error: class Object only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(21): Error: class Throwable only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(22): Error: class Exception only object.d can define this reserved class name
fail_compilation/imports/fail10277.d(23): Error: class Error only object.d can define this reserved class name
---
*/

import imports.fail10277;
23 changes: 23 additions & 0 deletions test/fail_compilation/imports/fail10277.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module imports.fail10277;

class TypeInfo { }
class TypeInfo_Class { }
class TypeInfo_Interface { }
class TypeInfo_Struct { }
class TypeInfo_Typedef { }
class TypeInfo_Pointer { }
class TypeInfo_Array { }
class TypeInfo_AssociativeArray { }
class TypeInfo_Enum { }
class TypeInfo_Function { }
class TypeInfo_Delegate { }
class TypeInfo_Tuple { }
class TypeInfo_Const { }
class TypeInfo_Invariant { }
class TypeInfo_Shared { }
class TypeInfo_Inout { }
class TypeInfo_Vector { }
class Object { }
class Throwable { }
class Exception { }
class Error { }

0 comments on commit 956eb92

Please sign in to comment.