www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22600] New: Better error message when trying to assign

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

          Issue ID: 22600
           Summary: Better error message when trying to assign
                    non-implicitily convertible slices
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: rumbu rumbu.ro

In the code below:


struct A { int x; }
struct B { int y; }
A[] bufa;
B[] bufb;
bufa[0] = bufb[0];

The error message is "cannot implicitly convert expression `bufb[0]` of type
`B` to `A`"

Trying to do a slice assignment:

bufa[] = bufb[];

will render another error message:

"cannot implicitly convert expression `bufb[]` of type `B[]` to `A[]".

Since the root cause is the first one, I think the error message must also
state that 'B' si not implicitily convertible to 'A' instead of highlight that
sorresponding slices are incompatible.

This example is simple, but if A and B are some long names (e.g. template
instantiations), the error message is difficult to gasp and makes you think
that is a problem with slice assignment, not with the basic assignment of B to
A.

--
Dec 14 2021