[Issue 22417] New: Slice assignment operator overloading example is incorrect
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Oct 18 03:50:25 UTC 2021
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 at puremagic.com
Reporter: snarwin+bugzilla at 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
--
More information about the Digitalmars-d-bugs
mailing list