[Issue 14632] New: Diagnostic improvement for invalid cast with alias this

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat May 30 06:52:09 PDT 2015


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

          Issue ID: 14632
           Summary: Diagnostic improvement for invalid cast with alias
                    this
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: k.hara.pg at gmail.com

Spin-off from issue 14093.

>From dmd test suite test/fail_compilation/fail_casting.d:

/*
TEST_OUTPUT:
---
fail_compilation/fail_casting.d(179): Error: cannot cast expression
__tup$n$.__expand_field_0 of type int to object.Object
fail_compilation/fail_casting.d(179): Error: cannot cast expression
__tup$n$.__expand_field_1 of type int to object.Object
---
*/
alias TypeTuple14093(T...) = T;
struct Tuple14093(T...)
{
    static if (T.length == 4)
    {
        alias Types = TypeTuple14093!(T[0], T[2]);

        Types expand;

        @property ref inout(Tuple14093!Types) _Tuple_super() inout @trusted
        {
            return *cast(typeof(return)*) &(expand[0]);
        }
        alias _Tuple_super this;
    }
    else
    {
        alias Types = T;
        Types expand;
        alias expand this;
    }
}
void test14093()
{
    Tuple14093!(int, "x", int, "y") point;
    auto newPoint = cast(Object)(point);   // line 179
}

The message can be better as follows:

Error: cannot cast expression point of type Tuple14093!(int, "x", int, "y") to
object.Object

--


More information about the Digitalmars-d-bugs mailing list