www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22982] New: Can't copy scope range elements into a returned

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

          Issue ID: 22982
           Summary: Can't copy scope range elements into a returned array
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: atila.neves gmail.com

This code should, but doesn't, compile:

---------------------
void main()  safe pure {
    import std.range : only;
    scope rng = only("foo", "bar");
    oops(rng);
}

auto oops(Range)(return scope Range range)  safe {
    import std.range : ElementEncodingType;
    ElementEncodingType!Range[] result;
    foreach(e; range)
        result ~= e;
    return result;
}
------------------------

d.d(13): Error: scope variable `e` may not be copied into allocated memory
d.d(6): Error: template instance `d.oops!(OnlyResult!(string, string))` error
instantiating

--
Apr 04 2022