www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23491] New: Nonsensical deprecation message when using delegate

https://issues.dlang.org/show_bug.cgi?id=23491

          Issue ID: 23491
           Summary: Nonsensical deprecation message when using delegate
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

Code:
```
import core.internal.string : unsignedToTempString;
void main ()  safe
{
    toString(null);
}
void toString (void delegate (char[])  safe sink)  safe
{
    char[20] buffer = void;
    sink(unsignedToTempString(42, buffer));
}

```

Message:
foo.d(9): Deprecation: reference to local variable `buffer` assigned to
non-scope parameter `__anonymous_param` calling ``

The actual problem is that the return value of `unsignedToTempString`, which is
a slice of `buffer`, is passed to the first argument of `sink` that is not
scope.
However, the message:
1) Doesn't name `sink` at all (The '``' is obviously a bug);
2) References `buffer` but not the return value of `unsignedToTempString`;
3) Doesn't handle anonymous params gracefully;

--
Nov 17 2022