On Fri, 06 May 2011 08:49:44 -0400, Jason House
<jason.james.ho...@gmail.com> wrote:
Steven Schveighoffer Wrote:
On Fri, 06 May 2011 03:39:31 -0400, Mariusz Gliwiński
<alienballa...@gmail.com> wrote:
> Is this bug, or is it as supposed to be? I'm not sure...
> <code>
> interface TmpI(T) {
> void func(T);
> }
>
> class TmpC {}
> class TmpC2 : TmpC {}
>
> class Tmp : TmpI!TmpC2 {
> void func(TmpI!TmpC) {};
Here is one problem, TmpI is instantiated with TmpC2 as the func
parameter, yet you use TmpI!TmpC as your func parameter. The func
parameter should be TmpC2. I'm surprised this part would compile
without
complaining that you didn't implement func. But it probably would fail
if
it got to that check.
This part is fine. When extending a class or interface, you are free to
widen the input and narrow the output. Users of the interface can pass
in TmpC2 (it's a valid TmpC)
But look at TmpI, if T is TmpC2, then func's param is TmpC2. This can't
be implemented with TmpI!TmpC.
Let's take templates out of it, and look at what is generated:
interface TmpI1 // in original exmample, this is TmpI!TmpC2
{
void func(TmpC2);
}
interface TmpI2 // in original example, this is TmpI!TmpC
{
void func(TmpC);
}
class Tmp : TmpI1
{
void func(TmpI2) {}
}
There is no way TmpI2 casts implicitly to or from TmpC2, they are
unrelated types.
-Steve