try out replacing Dsymbol.error() part 5 (#15663)

This commit is contained in:
Walter Bright 2023-10-09 19:48:25 -07:00 committed by GitHub
parent d78e21e030
commit afeeef2ac9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 26 deletions

View file

@ -468,7 +468,8 @@ extern (C++) final class Module : Package
!FileName.equalsExt(srcfilename, dd_ext))
{
error("source file name '%.*s' must have .%.*s extension",
error(loc, "%s `%s` source file name '%.*s' must have .%.*s extension",
kind, toPrettyChars,
cast(int)srcfilename.length, srcfilename.ptr,
cast(int)mars_ext.length, mars_ext.ptr);
fatal();
@ -593,7 +594,8 @@ extern (C++) final class Module : Package
}
if (FileName.equals(docfilename, srcfile.toString()))
{
error("source file and output file have same name '%s'", srcfile.toChars());
error(loc, "%s `%s` source file and output file have same name '%s'",
kind, toPrettyChars, srcfile.toChars());
fatal();
}
return FileName(docfilename);
@ -852,7 +854,7 @@ extern (C++) final class Module : Package
/* Check to see if module name is a valid identifier
*/
if (!Identifier.isValidIdentifier(this.ident.toChars()))
error("has non-identifier characters in filename, use module declaration instead");
error(loc, "%s `%s` has non-identifier characters in filename, use module declaration instead", kind, toPrettyChars);
}
// Insert module into the symbol table
Dsymbol s = this;
@ -941,7 +943,7 @@ extern (C++) final class Module : Package
return; // already done
if (filetype == FileType.ddoc)
{
error("is a Ddoc file, cannot import it");
error(loc, "%s `%s` is a Ddoc file, cannot import it", kind, toPrettyChars);
return;
}
@ -1479,7 +1481,8 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
if (buf.length & 3)
{
mod.error("odd length of UTF-32 char source %llu", cast(ulong) buf.length);
.error(mod.loc, "%s `%s` odd length of UTF-32 char source %llu",
mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
return null;
}
@ -1495,7 +1498,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
{
if (u > 0x10FFFF)
{
mod.error("UTF-32 value %08x greater than 0x10FFFF", u);
.error(mod.loc, "%s `%s` UTF-32 value %08x greater than 0x10FFFF", mod.kind, mod.toPrettyChars, u);
return null;
}
dbuf.writeUTF8(u);
@ -1525,7 +1528,7 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
if (buf.length & 1)
{
mod.error("odd length of UTF-16 char source %llu", cast(ulong) buf.length);
.error(mod.loc, "%s `%s` odd length of UTF-16 char source %llu", mod.kind, mod.toPrettyChars, cast(ulong) buf.length);
return null;
}
@ -1545,13 +1548,13 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
i++;
if (i >= eBuf.length)
{
mod.error("surrogate UTF-16 high value %04x at end of file", u);
.error(mod.loc, "%s `%s` surrogate UTF-16 high value %04x at end of file", mod.kind, mod.toPrettyChars, u);
return null;
}
const u2 = readNext(&eBuf[i]);
if (u2 < 0xDC00 || 0xE000 <= u2)
{
mod.error("surrogate UTF-16 low value %04x out of range", u2);
.error(mod.loc, "%s `%s` surrogate UTF-16 low value %04x out of range", mod.kind, mod.toPrettyChars, u2);
return null;
}
u = (u - 0xD7C0) << 10;
@ -1559,12 +1562,12 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
}
else if (u >= 0xDC00 && u <= 0xDFFF)
{
mod.error("unpaired surrogate UTF-16 value %04x", u);
.error(mod.loc, "%s `%s` unpaired surrogate UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
return null;
}
else if (u == 0xFFFE || u == 0xFFFF)
{
mod.error("illegal UTF-16 value %04x", u);
.error(mod.loc, "%s `%s` illegal UTF-16 value %04x", mod.kind, mod.toPrettyChars, u);
return null;
}
dbuf.writeUTF8(u);
@ -1623,7 +1626,8 @@ private const(char)[] processSource (const(ubyte)[] src, Module mod)
// It's UTF-8
if (buf[0] >= 0x80)
{
mod.error("source file must start with BOM or ASCII character, not \\x%02X", buf[0]);
auto loc = mod.getLoc();
.error(loc, "%s `%s` source file must start with BOM or ASCII character, not \\x%02X", mod.kind, mod.toPrettyChars, buf[0]);
return null;
}

View file

@ -273,7 +273,7 @@ extern (C++) class StructDeclaration : AggregateDeclaration
{
// .stringof is always defined (but may be hidden by some other symbol)
if(ident != Id.stringof && !(flags & IgnoreErrors) && semanticRun < PASS.semanticdone)
error("is forward referenced when looking for `%s`", ident.toChars());
.error(loc, "%s `%s` is forward referenced when looking for `%s`", kind, toPrettyChars, ident.toChars());
return null;
}

View file

@ -886,7 +886,7 @@ extern (C++) class Dsymbol : ASTNode
if (ident == Id.__sizeof ||
!(sc && sc.flags & SCOPE.Cfile) && (ident == Id.__xalignof || ident == Id._mangleof))
{
error("`.%s` property cannot be redefined", ident.toChars());
.error(loc, "%s `%s` `.%s` property cannot be redefined", kind, toPrettyChars, ident.toChars());
errors = true;
}
}
@ -1026,7 +1026,7 @@ extern (C++) class Dsymbol : ASTNode
*/
uinteger_t size(const ref Loc loc)
{
error("symbol `%s` has no size", toChars());
.error(loc, "%s `%s` symbol `%s` has no size", kind, toPrettyChars, toChars());
return SIZE_INVALID;
}
@ -1776,7 +1776,7 @@ public:
}
else
{
s1.error(s1.loc, "conflicts with %s `%s` at %s", 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.locToChars());
}
}

View file

@ -154,13 +154,13 @@ unittest
assert(sur16.module_ is null);
assert(diagnosticMessages.length == 7);
assert(diagnosticMessages[0] == "source file must start with BOM or ASCII character, not \\x84");
assert(diagnosticMessages[1] == "odd length of UTF-16 char source 3");
assert(diagnosticMessages[2] == "odd length of UTF-32 char source 3");
assert(diagnosticMessages[3] == "UTF-32 value 84810000 greater than 0x10FFFF");
assert(diagnosticMessages[4] == "illegal UTF-16 value ffff");
assert(diagnosticMessages[5] == "unpaired surrogate UTF-16 value dc00");
assert(diagnosticMessages[6] == "surrogate UTF-16 low value e000 out of range");
assert(endsWith(diagnosticMessages[0], "source file must start with BOM or ASCII character, not \\x84"));
assert(endsWith(diagnosticMessages[1], "odd length of UTF-16 char source 3"));
assert(endsWith(diagnosticMessages[2], "odd length of UTF-32 char source 3"));
assert(endsWith(diagnosticMessages[3], "UTF-32 value 84810000 greater than 0x10FFFF"));
assert(endsWith(diagnosticMessages[4], "illegal UTF-16 value ffff"));
assert(endsWith(diagnosticMessages[5], "unpaired surrogate UTF-16 value dc00"));
assert(endsWith(diagnosticMessages[6], "surrogate UTF-16 low value e000 out of range"));
}
@("initDMD - contract checking")
@ -271,8 +271,8 @@ unittest
}
});
assert(diagnosticMessages[0] == "no identifier for declarator `temp`");
assert(diagnosticMessages[1] == "found `==` instead of statement");
assert(endsWith(diagnosticMessages[0], "no identifier for declarator `temp`"));
assert(endsWith(diagnosticMessages[1], "found `==` instead of statement"));
}
@("addStringImport") unittest
@ -388,5 +388,10 @@ unittest
t.module_.fullSemantic();
assert(global.errors == 1);
assert(diagnosticMessages[0] == "is a Ddoc file, cannot import it");
assert(endsWith(diagnosticMessages[0], "is a Ddoc file, cannot import it"));
}
bool endsWith(string diag, string msg)
{
return diag.length >= msg.length && diag[$ - msg.length .. $] == msg;
}