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

          Issue ID: 20433
           Summary: Don't complain about implicit cast when an explicit
                    cast would also be in error
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: trivial
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

Consider:

struct Thing { int x; }
void main() {
    Thing a = [1];
}
// Error: cannot implicitly convert expression [1] of type int[] to Thing

The error message suggests that the implicitness of the conversion
is the problem. However, this also fails:

struct Thing { int x; }
void main() {
    Thing a = cast(Thing) [1];
}
// Error: cannot cast expression [1] of type int[] to Thing

So I suggest, as a trivial enhancement to dmd's error messages, that
'implicitly' be dropped from the first error when an explicit cast
would also fail.

The error messages would still not be the same ('convert' vs. 'cast'),
which might help the reader find the error in an expression with both
implicit conversions and explicit casts.

--

Reply via email to