digitalmars.D.learn - Is this bug or not?
- =?UTF-8?B?TWFyaXVzeiBHbGl3acWEc2tp?= (19/19) May 06 2011 Is this bug, or is it as supposed to be? I'm not sure...
- Steven Schveighoffer (12/25) May 06 2011 Here is one problem, TmpI is instantiated with TmpC2 as the func
- Jason House (2/22) May 06 2011 This part is fine. When extending a class or interface, you are free to ...
- Steven Schveighoffer (20/46) May 06 2011 But look at TmpI, if T is TmpC2, then func's param is TmpC2. This can't...
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) {}; } void main(string[] args) { auto inst = new Tmp; inst.func(new Tmp); } </code> Error: function tmp.Tmp.func (TmpI _param_0) is not callable using argument types (Tmp) Error: cannot implicitly convert expression (new Tmp) of type tmp.Tmp to tmp.TmpI!(TmpC).TmpI
May 06 2011
On Fri, 06 May 2011 03:39:31 -0400, Mariusz Gliwiński <alienballance 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.} void main(string[] args) { auto inst = new Tmp; inst.func(new Tmp);Here is the real problem, Tmp is not a TmpI!TmpC2, it's a TmpI!TmpC. So it cannot be cast (implicitly or explicitly). Implicit casting does not work for template parameters, in other words, TmpI!TmpC2 does not implicitly cast to TmpI!TmpC. -Steve
May 06 2011
Steven Schveighoffer Wrote:On Fri, 06 May 2011 03:39:31 -0400, Mariusz Gliwiński <alienballance gmail.com> wrote: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)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.
May 06 2011
On Fri, 06 May 2011 08:49:44 -0400, Jason House <jason.james.house gmail.com> wrote:Steven Schveighoffer Wrote: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. -SteveOn Fri, 06 May 2011 03:39:31 -0400, Mariusz Gliwiński <alienballance gmail.com> wrote: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)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.
May 06 2011