Bug 23295 – [dip1000] explain why scope inference failed

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-08-15T13:11:48Z
Last change time
2022-08-22T12:33:26Z
Keywords
pull
Assigned to
No Owner
Creator
Dennis

Comments

Comment #0 by dkorpel — 2022-08-15T13:11:48Z
This comes up a lot in Phobos when using range functions (e.g. `reduce` or `format`) that have a lot of overloads and design by introspection complexity, making the source of scope errors really hard to track down. Minimized example: ``` @safe: void main() { scope int* x; foo(x, null); } auto foo(int* y, int** w) { fooImpl(y, null); } auto fooImpl(int* z, int** w) { // <tons of code> auto f = &z; // <tons of code> } ``` The error is: > Error: scope variable `x` assigned to non-scope parameter `y` calling onlineapp.foo It doesn't tell you anything more than that, I would like the error to tell me: > Error: scope variable `x` assigned to non-scope parameter `y` > which is assigned to non-scope parameter `z` > which is not inferred `scope` because `&z`
Comment #1 by dlang-bot — 2022-08-16T12:37:13Z
@dkorpel created dlang/dmd pull request #14373 "Fix 23295 - explain why scope inference failed" fixing this issue: - Fix 23295 - explain why scope inference failed https://github.com/dlang/dmd/pull/14373