-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
Make safe error messages consistent #20654
Conversation
Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#20654" |
"copying `%s` into allocated memory escapes a reference to parameter `%s`" : | ||
"copying `%s` into allocated memory escapes a reference to local variable `%s`"; | ||
return setUnsafePreview(&sc, fs, gag, e.loc, msg, e, v); | ||
"escaping a reference to parameter `%s` by copying `%s` into allocated memory" : | ||
"escaping a reference to local variable `%s by copying `%s` into allocated memory"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dkorpel - this caused a diagnostic regression - there's a missing closing backtick in this format string.
Are you able to fix this? Alternatively can include it in the bundle of "broken DMD/C++ API" things I'm preparing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, give me a minute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are quite a few safety error messages, and some tell they are related to 'safe code' or
@safe
functions, while others don't. This is not only inconsistent, it's also false with-preview=safer
: some of these errors occur in functions without a@safe
annotation.This PR rewrites all safety error messages so they either form a noun or gerund: "pointer arithmetic" or "void initializing a pointer". The error reporter will then surround that in context:
deprecations: "{action} will become
@system
in the future"safe functions: "{action} is not allowed in a
@safe
function"safer functions: "{action} is not allowed in a function with default safety with
-preview=safer
"system variables: "{action} can't initialize
@safe
variable%s
"inferred supplemental error: "which wasn't safe because of: {action}"
Occasionally this requirement results in suggested fixes being phrased slightly awkwardly:
A future enhancement of adding supplemental errors to
setUnsafe
could improve this.