From b6781a8eae399e339951cd12429930f28c886c71 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Tue, 9 Dec 2008 01:56:39 +0100 Subject: [PATCH] Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error! Added a bit more information to the runtime's cyclic dependency detection exception. --- gen/toir.cpp | 11 +++++++++++ runtime/internal/genobj.d | 11 ++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gen/toir.cpp b/gen/toir.cpp index 1e5e987c..11829ce4 100644 --- a/gen/toir.cpp +++ b/gen/toir.cpp @@ -56,10 +56,18 @@ DValue* VarExp::toElem(IRState* p) LOG_SCOPE; assert(var); + if (VarDeclaration* vd = var->isVarDeclaration()) { Logger::println("VarDeclaration ' %s ' of type ' %s '", vd->toChars(), vd->type->toChars()); + // this is an error! must be accessed with DotVarExp + if (var->needThis()) + { + error("need 'this' to access member %s", toChars()); + fatal(); + } + // _arguments if (vd->ident == Id::_arguments && p->func()->_arguments) { @@ -144,6 +152,9 @@ DValue* VarExp::toElem(IRState* p) LLValue* val; if (!vd->ir.isSet() || !(val = vd->ir.getIrValue())) { + // FIXME: this error is bad! + // We should be VERY careful about adding errors in general, as they have + // a tendency to "mask" out the underlying problems ... error("variable %s not resolved", vd->toChars()); if (Logger::enabled()) Logger::cout() << "unresolved variable had type: " << *DtoType(vd->type) << '\n'; diff --git a/runtime/internal/genobj.d b/runtime/internal/genobj.d index 5a64b886..01499abb 100644 --- a/runtime/internal/genobj.d +++ b/runtime/internal/genobj.d @@ -1060,7 +1060,7 @@ extern (C) void _moduleCtor() _moduleinfo_dtors = new ModuleInfo[_moduleinfo_array.length]; debug(PRINTF) printf("_moduleinfo_dtors = x%x\n", cast(void *)_moduleinfo_dtors); _moduleIndependentCtors(); - _moduleCtor2(_moduleinfo_array, 0); + _moduleCtor2(null, _moduleinfo_array, 0); } extern (C) void _moduleIndependentCtors() @@ -1076,7 +1076,7 @@ extern (C) void _moduleIndependentCtors() debug(PRINTF) printf("_moduleIndependentCtors() DONE\n"); } -void _moduleCtor2(ModuleInfo[] mi, int skip) +void _moduleCtor2(ModuleInfo from, ModuleInfo[] mi, int skip) { debug(PRINTF) printf("_moduleCtor2(): %d modules\n", mi.length); for (uint i = 0; i < mi.length; i++) @@ -1096,11 +1096,12 @@ void _moduleCtor2(ModuleInfo[] mi, int skip) if (m.flags & MIctorstart) { if (skip || m.flags & MIstandalone) continue; - throw new Exception( "Cyclic dependency in module " ~ m.name ); + assert(from !is null); + throw new Exception( "Cyclic dependency in module " ~ from.name ~ " for import " ~ m.name); } m.flags |= MIctorstart; - _moduleCtor2(m.importedModules, 0); + _moduleCtor2(m, m.importedModules, 0); if (m.ctor) (*m.ctor)(); m.flags &= ~MIctorstart; @@ -1114,7 +1115,7 @@ void _moduleCtor2(ModuleInfo[] mi, int skip) else { m.flags |= MIctordone; - _moduleCtor2(m.importedModules, 1); + _moduleCtor2(m, m.importedModules, 1); } } debug(PRINTF) printf("_moduleCtor2() DONE\n");