www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21583] New: `array` is not ` safe` for a certain combination


          Issue ID: 21583
           Summary: `array` is not ` safe` for a certain combination of
                    `iota` and data types
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: industry, safe
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

I'm fairly certain the following should compile:
import std.range, std.array, std.algorithm;


struct Block { int[] data; }

public struct Height
    public ulong value;

    /// Provides implicit conversion to `ulong`
    public alias value this;

void main ()  safe
    auto x = getBlocksFrom(Height.init);

public auto getBlocksFrom (Height start_height)  safe nothrow
    auto r = iota(start_height, Height(42));
    auto r2 = r.map!(idx => const(Block).init);
    return r2.array;

Bug disappear if:
- The mapping is not to a `const(Block)`;
- I pass `ulong` or similar instead of `Height`;
- `Block` does not contain an array... Or if it's a `string`;

Jan 25 2021