D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23295 - [dip1000] explain why scope inference failed
Summary: [dip1000] explain why scope inference failed
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-08-15 13:11 UTC by Dennis
Modified: 2022-08-22 12:33 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dennis 2022-08-15 13:11:48 UTC
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 Dlang Bot 2022-08-16 12:37:13 UTC
@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