www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20938] New: Cannot create const arrays mixing immutable and

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

          Issue ID: 20938
           Summary: Cannot create const arrays mixing immutable and
                    mutable structs with indirections
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

```
struct Block { int[] ind; }
private immutable Block _gen;
ref immutable(Block) Genesis() { return _gen; }

void main ()
{
    Block block;

    // conv.d(10): Error: cannot implicitly convert expression Genesis() of
type immutable(Block) to Block
    auto a1 = [ Genesis(), block ];
    // conv.d(12): Error: cannot implicitly convert expression Genesis() of
type immutable(Block) to Block
    const a2 = [ Genesis(), block ];
    // conv.d(14): Error: cannot implicitly convert expression Genesis() of
type immutable(Block) to Block
    const(Block)[] a3 = [ Genesis(), block ];
    // conv.d(16): Error: cannot implicitly convert expression Genesis() of
type immutable(Block) to Block
    const(Block)[2] a4 = [ Genesis(), block ];
    // conv.d(18): Error: cannot implicitly convert expression block of type
Block to immutable(Block)
    const(Block)[] a5 = [ block, Genesis() ];
}
```

Marking as critical because inference not working is one thing, but the error
on `const(Block)[]` is a rejects-valid and the error message is quite
confusing.

--
Jun 16 2020