diff --git a/compiler/src/dmd/dmodule.d b/compiler/src/dmd/dmodule.d index 4e9e491cea..e07e91c65c 100644 --- a/compiler/src/dmd/dmodule.d +++ b/compiler/src/dmd/dmodule.d @@ -632,7 +632,7 @@ extern (C++) final class Module : Package const name = srcfile.toString(); if (FileName.equals(name, "object.d")) { - ObjectNotFound(loc, ident); + ObjectNotFound(Loc.initial, ident); } else if (FileName.ext(this.arg) || !loc.isValid()) { @@ -1408,7 +1408,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod) { enum SourceEncoding { utf16, utf32} enum Endian { little, big} - immutable loc = mod.getLoc(); + immutable loc = mod.loc; /* * Convert a buffer from UTF32 to UTF8 diff --git a/compiler/src/dmd/dsymbol.d b/compiler/src/dmd/dsymbol.d index 180bddb2c1..90ac4a1b7c 100644 --- a/compiler/src/dmd/dsymbol.d +++ b/compiler/src/dmd/dsymbol.d @@ -344,19 +344,6 @@ extern (C++) class Dsymbol : ASTNode return toChars(); } - final const(Loc) getLoc() - { - if (!loc.isValid()) // avoid bug 5861. - if (const m = getModule()) - return Loc(m.srcfile.toChars(), 0, 0); - return loc; - } - - final const(char)* locToChars() - { - return getLoc().toChars(); - } - override bool equals(const RootObject o) const { if (this == o) @@ -1303,7 +1290,7 @@ public: } else { - .error(s1.loc, "%s `%s` conflicts with %s `%s` at %s", s1.kind, s1.toPrettyChars, s2.kind(), s2.toPrettyChars(), s2.locToChars()); + .error(s1.loc, "%s `%s` conflicts with %s `%s` at %s", s1.kind, s1.toPrettyChars, s2.kind(), s2.toPrettyChars(), s2.loc.toChars()); } } diff --git a/compiler/src/dmd/dsymbol.h b/compiler/src/dmd/dsymbol.h index 23cbf763e9..e3bf30179c 100644 --- a/compiler/src/dmd/dsymbol.h +++ b/compiler/src/dmd/dsymbol.h @@ -195,8 +195,6 @@ public: CPPNamespaceDeclaration* cppnamespace(CPPNamespaceDeclaration* ns); UserAttributeDeclaration* userAttribDecl(UserAttributeDeclaration* uad); virtual const char *toPrettyCharsHelper(); // helper to print fully qualified (template) arguments - Loc getLoc(); - const char *locToChars(); bool equals(const RootObject * const o) const override; bool isAnonymous() const; Module *getModule(); diff --git a/compiler/src/dmd/dsymbolsem.d b/compiler/src/dmd/dsymbolsem.d index c2f8bdfc03..a93c1596d8 100644 --- a/compiler/src/dmd/dsymbolsem.d +++ b/compiler/src/dmd/dsymbolsem.d @@ -6813,7 +6813,7 @@ extern(C++) class ImportAllVisitor : Visitor (*m.members)[0].ident != Id.object || (*m.members)[0].isImport() is null)) { - auto im = new Import(Loc.initial, null, Id.object, null, 0); + auto im = new Import(m.loc, null, Id.object, null, 0); m.members.shift(im); } if (!m.symtab) diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 47f2343a65..895041bfaf 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -474,8 +474,6 @@ public: CPPNamespaceDeclaration* cppnamespace(CPPNamespaceDeclaration* ns); UserAttributeDeclaration* userAttribDecl(UserAttributeDeclaration* uad); virtual const char* toPrettyCharsHelper(); - const Loc getLoc(); - const char* locToChars(); bool equals(const RootObject* const o) const override; bool isAnonymous() const; Module* getModule(); diff --git a/compiler/src/dmd/glue.d b/compiler/src/dmd/glue.d index 9f605685dc..04b15105d2 100644 --- a/compiler/src/dmd/glue.d +++ b/compiler/src/dmd/glue.d @@ -280,7 +280,7 @@ private void obj_write_deferred(ref OutBuffer objbuf, Library library, ref Dsymb { Identifier id = Identifier.create(idbuf.extractChars()); - Module md = new Module(mnames, id, 0, 0); + Module md = new Module(m.loc, mnames, id, 0, 0); md.members = new Dsymbols(); md.members.push(s); // its only 'member' is s md.doppelganger = 1; // identify this module as doppelganger diff --git a/compiler/src/dmd/mars.d b/compiler/src/dmd/mars.d index edbe16471b..a32f838d5f 100644 --- a/compiler/src/dmd/mars.d +++ b/compiler/src/dmd/mars.d @@ -1814,6 +1814,7 @@ bool createModule(const(char)* file, ref Strings libmodules, const ref Target ta } const(char)[] p = FileName.name(file.toDString()); // strip path const(char)[] ext = FileName.ext(p); + Loc loc = Loc(file, 0, 0); if (!ext) { if (!p.length) @@ -1822,7 +1823,7 @@ bool createModule(const(char)* file, ref Strings libmodules, const ref Target ta return true; } auto id = Identifier.idPool(p); - m = new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput); + m = new Module(loc, file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput); return false; } @@ -1902,8 +1903,7 @@ bool createModule(const(char)* file, ref Strings libmodules, const ref Target ta * its path and extension. */ auto id = Identifier.idPool(name); - - m = new Module(file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput); + m = new Module(loc, file.toDString, id, global.params.ddoc.doOutput, global.params.dihdr.doOutput); return false; } eSink.error(Loc.initial, "unrecognized file extension %.*s", cast(int)ext.length, ext.ptr); @@ -1954,7 +1954,7 @@ bool createModules(ref Strings files, ref Strings libmodules, const ref Target t /// Returns: a compiled module (semantic3) containing an empty main() function, for the -main flag Module moduleWithEmptyMain() { - auto result = new Module("__main.d", Identifier.idPool("__main"), false, false); + auto result = new Module(Loc.initial, "__main.d", Identifier.idPool("__main"), false, false); // need 2 trailing nulls for sentinel and 2 for lexer auto data = arraydup("version(D_BetterC)extern(C)int main(){return 0;}else int main(){return 0;}\0\0\0\0"); result.src = cast(ubyte[]) data[0 .. $-4]; diff --git a/compiler/src/dmd/traits.d b/compiler/src/dmd/traits.d index e065975c67..13023d91c3 100644 --- a/compiler/src/dmd/traits.d +++ b/compiler/src/dmd/traits.d @@ -1991,9 +1991,9 @@ Expression semanticTraits(TraitsExp e, Scope* sc) return dimError(1); auto arg0 = (*e.args)[0]; Dsymbol s = getDsymbolWithoutExpCtx(arg0); - if (!s || !s.loc.isValid()) + if (!s || !s.loc.isValid() || s.isModule()) { - error(e.loc, "can only get the location of a symbol, not `%s`", arg0.toChars()); + error(e.loc, "can only get the location of a symbol, not `%s`", s ? s.toPrettyChars() : arg0.toChars()); return ErrorExp.get(); } diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index c6306021c8..20de4fa047 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -2712,23 +2712,21 @@ Type typeSemantic(Type type, const ref Loc loc, Scope* sc) which isn't a particularly good error message (x is a variable?). */ Dsymbol varDecl = mtype.toDsymbol(sc); - const(Loc) varDeclLoc = varDecl.getLoc(); Module varDeclModule = varDecl.getModule(); //This can be null .error(loc, "variable `%s` is used as a type", mtype.toChars()); //Check for null to avoid https://issues.dlang.org/show_bug.cgi?id=22574 if ((varDeclModule !is null) && varDeclModule != sc._module) // variable is imported { - const(Loc) varDeclModuleImportLoc = varDeclModule.getLoc(); .errorSupplemental( - varDeclModuleImportLoc, + varDeclModule.loc, "variable `%s` is imported here from: `%s`", varDecl.toChars, varDeclModule.toPrettyChars, ); } - .errorSupplemental(varDeclLoc, "variable `%s` is declared here", varDecl.toChars); + .errorSupplemental(varDecl.loc, "variable `%s` is declared here", varDecl.toChars); } else .error(loc, "`%s` is used as a type", mtype.toChars()); diff --git a/compiler/test/fail_compilation/trait_loc_err.d b/compiler/test/fail_compilation/trait_loc_err.d index c5d0579f4a..2916214411 100644 --- a/compiler/test/fail_compilation/trait_loc_err.d +++ b/compiler/test/fail_compilation/trait_loc_err.d @@ -1,8 +1,9 @@ /* TEST_OUTPUT: --- -fail_compilation/trait_loc_err.d(13): Error: can only get the location of a symbol, not `trait_loc_err` -fail_compilation/trait_loc_err.d(14): Error: can only get the location of a symbol, not `stdc` +fail_compilation/trait_loc_err.d(14): Error: can only get the location of a symbol, not `trait_loc_err` +fail_compilation/trait_loc_err.d(15): Error: can only get the location of a symbol, not `core.stdc` +fail_compilation/trait_loc_err.d(16): Error: can only get the location of a symbol, not `core.stdc.stdio` --- */ module trait_loc_err; @@ -12,4 +13,5 @@ void main() { __traits(getLocation, __traits(parent, main)); __traits(getLocation, __traits(parent, core.stdc.stdio)); + __traits(getLocation, core.stdc.stdio); }