Bug 14632 – Diagnostic improvement for invalid cast with alias this
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-30T13:52:09Z
Last change time
2018-11-26T15:54:53Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Kenji Hara
Comments
Comment #0 by k.hara.pg — 2015-05-30T13:52:09Z
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
Comment #1 by nick — 2018-06-09T11:35:02Z
Reduced:
struct Tuple(T...)
{
alias Types = T;
Types expand;
alias expand this;
}
void test()
{
Tuple!(int, int) point;
auto newPoint = cast(Object)(point);
}
Error messages no longer use '__tup$n$' but could still be improved as per comment 0:
onlineapp.d(10): Error: cannot cast expression point.__expand_field_0 of type int to object.Object
onlineapp.d(10): Error: cannot cast expression point.__expand_field_1 of type int to object.Object
Comment #2 by github-bugzilla — 2018-11-26T15:54:52Z