Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[func.d] move errorSupplementalInferredAttr to expressionsem.d #16937

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/src/dmd/canthrow.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import dmd.declaration;
import dmd.dsymbol;
import dmd.errorsink;
import dmd.expression;
import dmd.expressionsem : errorSupplementalInferredAttr;
import dmd.func;
import dmd.globals;
import dmd.init;
Expand Down
65 changes: 65 additions & 0 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,71 @@ void checkOverriddenDtor(FuncDeclaration f, Scope* sc, const ref Loc loc,
}
}

/// Print the reason why `fd` was inferred `@system` as a supplemental error
/// Params:
/// fd = function to check
/// maxDepth = up to how many functions deep to report errors
/// deprecation = print deprecations instead of errors
/// stc = storage class of attribute to check
public void errorSupplementalInferredAttr(FuncDeclaration fd, int maxDepth, bool deprecation, STC stc)
{
auto errorFunc = deprecation ? &deprecationSupplemental : &errorSupplemental;

AttributeViolation* s;
const(char)* attr;
if (stc & STC.safe)
{
s = fd.safetyViolation;
attr = "@safe";
}
else if (stc & STC.pure_)
{
s = fd.pureViolation;
attr = "pure";
}
else if (stc & STC.nothrow_)
{
s = fd.nothrowViolation;
attr = "nothrow";
}
else if (stc & STC.nogc)
{
s = fd.nogcViolation;
attr = "@nogc";
}

if (!s)
return;

if (s.fmtStr)
{
errorFunc(s.loc, deprecation ?
"which wouldn't be `%s` because of:" :
"which wasn't inferred `%s` because of:", attr);
if (stc == STC.nogc || stc == STC.pure_)
{
auto f = (cast(Dsymbol) s.arg0).isFuncDeclaration();
errorFunc(s.loc, s.fmtStr, f.kind(), f.toPrettyChars(), s.arg1 ? s.arg1.toChars() : "");
}
else
{
errorFunc(s.loc, s.fmtStr,
s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
}
}
else if (auto sa = s.arg0.isDsymbol())
{
if (FuncDeclaration fd2 = sa.isFuncDeclaration())
{
if (maxDepth > 0)
{
errorFunc(s.loc, "which calls `%s`", fd2.toPrettyChars());
errorSupplementalInferredAttr(fd2, maxDepth - 1, deprecation, stc);
}
}
}
}

/*******************************************
* Accessing variable v.
* Check for purity and safety violations.
Expand Down
65 changes: 0 additions & 65 deletions compiler/src/dmd/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -2066,68 +2066,3 @@ struct AttributeViolation
/// ditto
RootObject arg2 = null;
}

/// Print the reason why `fd` was inferred `@system` as a supplemental error
/// Params:
/// fd = function to check
/// maxDepth = up to how many functions deep to report errors
/// deprecation = print deprecations instead of errors
/// stc = storage class of attribute to check
void errorSupplementalInferredAttr(FuncDeclaration fd, int maxDepth, bool deprecation, STC stc)
{
auto errorFunc = deprecation ? &deprecationSupplemental : &errorSupplemental;

AttributeViolation* s;
const(char)* attr;
if (stc & STC.safe)
{
s = fd.safetyViolation;
attr = "@safe";
}
else if (stc & STC.pure_)
{
s = fd.pureViolation;
attr = "pure";
}
else if (stc & STC.nothrow_)
{
s = fd.nothrowViolation;
attr = "nothrow";
}
else if (stc & STC.nogc)
{
s = fd.nogcViolation;
attr = "@nogc";
}

if (!s)
return;

if (s.fmtStr)
{
errorFunc(s.loc, deprecation ?
"which wouldn't be `%s` because of:" :
"which wasn't inferred `%s` because of:", attr);
if (stc == STC.nogc || stc == STC.pure_)
{
auto f = (cast(Dsymbol) s.arg0).isFuncDeclaration();
errorFunc(s.loc, s.fmtStr, f.kind(), f.toPrettyChars(), s.arg1 ? s.arg1.toChars() : "");
}
else
{
errorFunc(s.loc, s.fmtStr,
s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
}
}
else if (auto sa = s.arg0.isDsymbol())
{
if (FuncDeclaration fd2 = sa.isFuncDeclaration())
{
if (maxDepth > 0)
{
errorFunc(s.loc, "which calls `%s`", fd2.toPrettyChars());
errorSupplementalInferredAttr(fd2, maxDepth - 1, deprecation, stc);
}
}
}
}
Loading