From 703ae01849d80e27c58e0bbf73d79e9707e4672b Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Sat, 5 Oct 2024 15:13:13 +0800 Subject: [PATCH] [func.d] move `errorSupplementalInferredAttr` to expressionsem.d all but one of its uses are there, the other is in `canthrow.d` --- compiler/src/dmd/canthrow.d | 1 + compiler/src/dmd/expressionsem.d | 65 ++++++++++++++++++++++++++++++++ compiler/src/dmd/func.d | 65 -------------------------------- 3 files changed, 66 insertions(+), 65 deletions(-) diff --git a/compiler/src/dmd/canthrow.d b/compiler/src/dmd/canthrow.d index dfc91e1c852..5738ae37afc 100644 --- a/compiler/src/dmd/canthrow.d +++ b/compiler/src/dmd/canthrow.d @@ -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; diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 950529d72a7..05f5386f32a 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -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. diff --git a/compiler/src/dmd/func.d b/compiler/src/dmd/func.d index 9d59fc99104..996b4377405 100644 --- a/compiler/src/dmd/func.d +++ b/compiler/src/dmd/func.d @@ -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); - } - } - } -}