www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20731] New: checkaction=context fails for structs with 'alias

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

          Issue ID: 20731
           Summary: checkaction=context fails for structs with 'alias
                    <slice> this'
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody puremagic.com
          Reporter: moonlightsentinel disroot.org

The following snippet causes a compilation failure / wrong formatting depending
on whether a is const/mutable:

----------------------------------------------
struct S
{
    int[2] arr;
    int[] get() { return arr[]; }
    alias get this;
}

const a = S([1, 2]);
assert(a == S([3, 4]);
-----------------------------------------------

Mutable: "[1, 2] != [3, 4]" instead of "S([1, 2]) != S([3, 4])".

Const: "Mutable method `get` is not callable using a `const` object!"

--
Apr 12