On 2/6/18 3:29 AM, Kagamin wrote:
On Monday, 5 February 2018 at 15:33:02 UTC, Steven Schveighoffer wrote:
Is there a more pragmatic use case why this should be possible?
Maybe for least surprise. The error message almost convinced me that
such cast is impossible, only because of my memory that this cast used
to be possible kept me trying. Is 5 not good because it's not big enough?
Honestly, I don't know why it's not working. But maybe there is a reason
(i.e. it's not a bug and was done on purpose).
All I meant is that, if you have a more practical correct reason for
casting an integer literal to an interface, then we can show that it's
worth worrying about.
By illustration of what I'm talking about, D complains about this:
int * foo()
{
int x;
return &x;
}
But not this:
int * bar()
{
int x;
int *p = &x;
return p;
}
Complaining about not being able to cast 5 directly to an interface,
when you can do it in 2 statements, may be like complaining that bar
compiles, why not foo?
-Steve