www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19015] New: arr[i..i] = c doesn't lower to a.opIndexAssign(c,


          Issue ID: 19015
           Summary: arr[i..i] = c doesn't lower to a.opIndexAssign(c,
                    a.opSlice(i, j))
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: greensunny12 gmail.com

According to the docs
this should work as:

  Expressions of the form a[i..j] = c are rewritten as a.opIndexAssign(c,
a.opSlice(i, j)), and a[] = c as a.opIndexAssign(c).
--- struct Foo { int payload; auto ref opSlice(size_t start, size_t end) { return this; } auto opIndexAssign(T)(T elem, Foo foo) { pragma(msg, "opIndexAssign"); return this; } } void main(string[] args) { Foo foo; pragma(msg, typeof(foo[0..2])); foo[0..2] = 3; } --- However, it fails with
 test.d(20): Error: cannot implicitly convert expression 3 of type int to Foo
AFAICT there's no reason why this lowering should fail (and at the very least, the error message needs to be improved). As a workaround the legacy opSliceAssign can be used and looking at Phobos only opSliceAssign is used and there's no use of this specific newer opIndexAssign lowering. --
Jun 22 2018