dip1000 and preview in combine to cause extra safety errors

Mathias LANG pro.mathias.lang at gmail.com
Wed Jun 8 17:09:49 UTC 2022


On Wednesday, 8 June 2022 at 14:52:53 UTC, Steven Schveighoffer 
wrote:
> ```d
> string foo(in string s)
> {
>     return s;
> }
>
> void main()
> {
>     import std.stdio;
>     string[] result;
>     foreach(c; "hello")
>     {
>         result ~= foo([c]);
>     }
>     writeln(result);
> }
> ```
>

This has nothing to do with `-preview=in`.
Change `foo`'s signature to:
> string foo(scope string s)

And you'll see the bug, even without `-preview=dip1000`.

Why is this happening ? You correctly guessed, because the 
frontend wrongfully lets the `string` go on the stack instead of 
allocating with it.

Some of the changes for DIP1000 made it to releases even without 
the switch, that's one example.


More information about the Digitalmars-d mailing list