www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22417] New: Slice assignment operator overloading example is


          Issue ID: 22417
           Summary: Slice assignment operator overloading example is
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dlang.org
          Assignee: nobody puremagic.com
          Reporter: snarwin+bugzilla gmail.com

The example in the language spec under "Slice Assignment Operator Overloading"
[1] is incorrect. Specifically, it claims that the following rewrite is

a[3..4] = v;  // same as a.opIndexAssign(v, a.opSlice(3,4));

However, using the -vcg-ast compiler switch reveals that this statement is
actually rewritten as follows:

a.opSlice(3LU, 4LU)[] = v;

This is because the D2-style opSlice overload is declared incorrectly: it does
not accept a `dim` template parameter, as specified in the section on "Slice
Operator Overloading" [2], and it returns an `int[2]` rather than the
`size_t[2]` expected by the opIndexAssign overload.

[1] https://dlang.org/spec/operatoroverloading.html#slice_assignment_operator
[2] https://dlang.org/spec/operatoroverloading.html#slice

Oct 17 2021