Skip to content

Commit

Permalink
fix Issue 23928 - improve error msg: scope variable s assigned to non…
Browse files Browse the repository at this point in the history
…-scope parameter this calling abc
  • Loading branch information
WalterBright committed May 19, 2023
1 parent 6e604e2 commit 7ec2d3c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/src/dmd/escape.d
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,18 @@ bool checkParamArgumentEscape(Scope* sc, FuncDeclaration fdc, Identifier parId,
desc ~ " `%s` assigned to non-scope parameter calling `assert()`", v);
return;
}

bool isThis = fdc && fdc.needThis() && fdc.vthis == vPar; // implicit `this` parameter to member function

const(char)* msg =
(isThis) ? (desc ~ " `%s` calling non-scope member function `%s.%s()`") :
(fdc && parId) ? (desc ~ " `%s` assigned to non-scope parameter `%s` calling `%s`") :
(fdc && !parId) ? (desc ~ " `%s` assigned to non-scope anonymous parameter calling `%s`") :
(!fdc && parId) ? (desc ~ " `%s` assigned to non-scope parameter `%s`") :
(desc ~ " `%s` assigned to non-scope anonymous parameter");

if (sc.setUnsafeDIP1000(gag, arg.loc, msg, v, parId ? parId : fdc, fdc))
auto param = isThis ? v : (parId ? parId : fdc);
if (sc.setUnsafeDIP1000(gag, arg.loc, msg, v, param, fdc))
{
result = true;
printScopeFailure(previewSupplementalFunc(sc.isDeprecated(), global.params.useDIP1000), vPar, 10);
Expand Down

0 comments on commit 7ec2d3c

Please sign in to comment.