Merge pull request #14255 from Geod24/useful-attributes-error

Print the inference error trace for regular inference errors

Signed-off-by: Dennis <dkorpel@users.noreply.github.com>
Signed-off-by: Nicholas Wilson <thewilsonator@users.noreply.github.com>
Merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
This commit is contained in:
The Dlang Bot 2022-07-11 19:23:17 +00:00 committed by GitHub
commit b156f0a9fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 20 deletions

View file

@ -13133,26 +13133,26 @@ bool checkSharedAccess(Expression e, Scope* sc, bool returnRef = false)
bool checkAddressVar(Scope* sc, Expression exp, VarDeclaration v)
{
//printf("checkAddressVar(exp: %s, v: %s)\n", exp.toChars(), v.toChars());
if (v)
if (v is null)
return true;
if (!v.canTakeAddressOf())
{
if (!v.canTakeAddressOf())
exp.error("cannot take address of `%s`", exp.toChars());
return false;
}
if (sc.func && !sc.intypeof && !v.isDataseg())
{
const(char)* p = v.isParameter() ? "parameter" : "local";
v.storage_class &= ~STC.maybescope;
v.doNotInferScope = true;
if (global.params.useDIP1000 != FeatureState.enabled &&
!(v.storage_class & STC.temp) &&
sc.setUnsafe())
{
exp.error("cannot take address of `%s`", exp.toChars());
exp.error("cannot take address of %s `%s` in `@safe` function `%s`", p, v.toChars(), sc.func.toChars());
return false;
}
if (sc.func && !sc.intypeof && !v.isDataseg())
{
const(char)* p = v.isParameter() ? "parameter" : "local";
v.storage_class &= ~STC.maybescope;
v.doNotInferScope = true;
if (global.params.useDIP1000 != FeatureState.enabled &&
!(v.storage_class & STC.temp) &&
sc.setUnsafe())
{
exp.error("cannot take address of %s `%s` in `@safe` function `%s`", p, v.toChars(), sc.func.toChars());
return false;
}
}
}
return true;
}

View file

@ -4466,12 +4466,15 @@ void errorSupplementalInferredSafety(FuncDeclaration fd, int maxDepth, bool depr
errorFunc(s.loc, s.fmtStr,
s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : "");
}
else if (FuncDeclaration fd2 = cast(FuncDeclaration) s.arg0)
else if (s.arg0.dyncast() == DYNCAST.dsymbol)
{
if (maxDepth > 0)
if (FuncDeclaration fd2 = (cast(Dsymbol) s.arg0).isFuncDeclaration())
{
errorFunc(s.loc, "which calls `%s`", fd2.toPrettyChars());
errorSupplementalInferredSafety(fd2, maxDepth - 1, deprecation);
if (maxDepth > 0)
{
errorFunc(s.loc, "which calls `%s`", fd2.toPrettyChars());
errorSupplementalInferredSafety(fd2, maxDepth - 1, deprecation);
}
}
}
}