www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16473] New: operator overloading is brocken

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

          Issue ID: 16473
           Summary: operator overloading is brocken
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ilyayaroshenko gmail.com

-------------------------------------------
import std.experimental.ndslice;

void main()
{
    auto sl = new double[10].sliced(2, 5);
    auto d = -sl[0, 1];
}
-------------------------------------------
/d921/f269.d(6): Error: template std.experimental.ndslice.slice.Slice!(2LU,
double*).Slice.opIndexUnary cannot deduce function from argument types
!("-")(int, int), candidates are:
/opt/compilers/dmd2/include/std/experimental/ndslice/slice.d(1980):       
std.experimental.ndslice.slice.Slice!(2LU, double*).Slice.opIndexUnary(string
op, Indexes...)(Indexes _indexes) if (isFullPureIndex!Indexes && (op == "++" ||
op == "--"))
/opt/compilers/dmd2/include/std/experimental/ndslice/slice.d(2008):       
std.experimental.ndslice.slice.Slice!(2LU, double*).Slice.opIndexUnary(string
op, Slices...)(Slices slices) if (isFullPureSlice!Slices && (op == "++" || op
== "--"))
-------------

The are two prototypes in Slice. Both with if (op == "++" || op == "--")
condition.
So, I don't think we need to add all opIndexUnary variants.
Instead, if expression -sl[0, 1] can not be expanded with opIndexUnary, then is
should be expanded with -(sl.opIndex(0, 1)).

--
Sep 06 2016