Skip to content

Commit

Permalink
split AttributeViolation into two distinct uses
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright authored and dlang-bot committed Nov 24, 2024
1 parent 726b9bb commit 4ba3411
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
10 changes: 9 additions & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,14 @@ public void errorSupplementalInferredAttr(FuncDeclaration fd, int maxDepth, bool
s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
}
}
else if (s.fd)
{
if (maxDepth > 0)
{
errorFunc(s.loc, "which calls `%s`", s.fd.toPrettyChars());
errorSupplementalInferredAttr(s.fd, maxDepth - 1, deprecation, stc, eSink);
}
}
else if (auto sa = s.arg0.isDsymbol())
{
if (FuncDeclaration fd2 = sa.isFuncDeclaration())
Expand Down Expand Up @@ -2284,7 +2292,7 @@ private bool checkSafety(FuncDeclaration f, ref Loc loc, Scope* sc)
else if (!sc.func.safetyViolation)
{
import dmd.func : AttributeViolation;
sc.func.safetyViolation = new AttributeViolation(loc, null, f, null, null);
sc.func.safetyViolation = new AttributeViolation(loc, f);
}
}
return false;
Expand Down
10 changes: 9 additions & 1 deletion compiler/src/dmd/funcsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,15 @@ extern (D) bool setImpure(FuncDeclaration fd, Loc loc = Loc.init, const(char)* f
if (fmt)
fd.pureViolation = new AttributeViolation(loc, fmt, fd, arg0); // impure action
else if (arg0)
fd.pureViolation = new AttributeViolation(loc, fmt, arg0); // call to impure function
{
if (auto sa = arg0.isDsymbol())
{
if (FuncDeclaration fd2 = sa.isFuncDeclaration())
{
fd.pureViolation = new AttributeViolation(loc, fd2); // call to impure function
}
}
}

if (fd.fes)
fd.fes.func.setImpure(loc, fmt, arg0);
Expand Down
10 changes: 9 additions & 1 deletion compiler/src/dmd/nogc.d
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,15 @@ extern (D) bool setGC(FuncDeclaration fd, Loc loc, const(char)* fmt, RootObject
if (fmt)
fd.nogcViolation = new AttributeViolation(loc, fmt, fd, arg0); // action that requires GC
else if (arg0)
fd.nogcViolation = new AttributeViolation(loc, fmt, arg0); // call to non-@nogc function
{
if (auto sa = arg0.isDsymbol())
{
if (FuncDeclaration fd2 = sa.isFuncDeclaration())
{
fd.nogcViolation = new AttributeViolation(loc, fd2); // call to non-@nogc function
}
}
}

fd.type.toTypeFunction().isNogc = false;
if (fd.fes)
Expand Down
17 changes: 13 additions & 4 deletions compiler/src/dmd/safe.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dmd.dcast : implicitConvTo;
import dmd.dclass;
import dmd.declaration;
import dmd.dscope;
import dmd.dsymbol;
import dmd.dsymbolsem : determineSize;
import dmd.errors;
import dmd.expression;
Expand Down Expand Up @@ -344,7 +345,7 @@ bool isTrusted(FuncDeclaration fd)
* fd = function we're gonna rat on
* gag = suppress error message (used in escape.d)
* loc = location of error
* format = printf-style format string
* format = printf-style format string
* arg0 = (optional) argument for first %s format specifier
* arg1 = (optional) argument for second %s format specifier
* arg2 = (optional) argument for third %s format specifier
Expand All @@ -354,8 +355,15 @@ extern (D) void reportSafeError(FuncDeclaration fd, bool gag, Loc loc,
{
if (fd.type.toTypeFunction().trust == TRUST.system) // function was just inferred to be @system
{
if (format || arg0)
if (format)
fd.safetyViolation = new AttributeViolation(loc, format, arg0, arg1, arg2);
else if (arg0)
{
if (FuncDeclaration fd2 = (cast(Dsymbol) arg0).isFuncDeclaration())
{
fd.safetyViolation = new AttributeViolation(loc, fd2); // call to non-@nogc function
}
}
}
else if (fd.isSafe())
{
Expand Down Expand Up @@ -421,7 +429,7 @@ extern (D) bool setUnsafeCall(FuncDeclaration fd, FuncDeclaration f)
* arg0 = (optional) argument for first %s format specifier
* arg1 = (optional) argument for second %s format specifier
* arg2 = (optional) argument for third %s format specifier
* Returns: whether there's a safe error
* Returns: whether there is a safe error
*/
bool setUnsafe(Scope* sc,
bool gag = false, Loc loc = Loc.init, const(char)* format = null,
Expand Down Expand Up @@ -499,7 +507,8 @@ bool setUnsafe(Scope* sc,
bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* format,
RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null)
{
//printf("setUnsafePreview() fs:%d %s\n", fs, format);
//printf("setUnsafePreview() fs:%d %s\n", fs, fmt);
assert(format);
with (FeatureState) final switch (fs)
{
case disabled:
Expand Down

0 comments on commit 4ba3411

Please sign in to comment.