www.digitalmars.com         C & C++   DMDScript  

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

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

          Issue ID: 22417
           Summary: Slice assignment operator overloading example is
                    incorrect
           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
performed:

---
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