[Mono-list] removing delegate
Daniel Stodden
stodden@cs.tum.edu
04 Aug 2002 02:20:54 +0200
On Sun, 2002-08-04 at 01:44, YUAN-FEN KUO wrote:
[cc'd to mono-dev]
> I think the follwoing piece of code will make my question clear:
>
>
> delegate void delA();
> delegate void delB();
>
> class main{
> static void Main(){
> delA food;
> delA aoo = new delA(aa);
> delB boo = new delB(aa);
> delA coo = new delA(aa);
>
> //legal combine
> food += aoo;
> food();
>
> //combine wrong type
> //food += boo; //throws exception as expected during runtime, though I
> wonder why not compile time
> //food();
>
> //revomve wrong type
> food -= boo; //does not throw any exceptions though type
> mismathched??
> food();
>
> //legal remove
> //"Attempting to remove a delegate from an empty list (or to remove a
> non-existent delegate from a non-empty list) is not an error" is said in the last
> paragraph of Secion 15.3
> //"Impossible Removal is benign" was used in their sample code in
> Sec. 15.3 as well.
> food -= coo;
> food();
>
> }
>
> static void aa(){System.Console.WriteLine("method aa");}
>
> }
just tried it. this is indeed helpful.
first, there is a bug in mcs. removing the wrong type (food-=boo) should
not be allowed by the compiler.
second, no mscli does not throw on food-=boo. it never does as i pointed
out. but what's _really_ interesting here is that (given an actual
assembly as written above) food -= boo actually suceeds, leaving you
with a null ref.
running mono, the second food() gets you a second call to aa().
running mscli, the second food() already bails out on null.
i'll have to look into this. you may file a bug for the mcs gang in the
mean time if you want to [if there isn't one already].
thanks a lot, i hate you ;),
daniel
> > > It seems that type mismatching isn't caught when removing a
> > delegate from a
> > > sequence of delegates.
> > > I am just wondering if this were done to match the Spec's saying
> > that
> > > "impossible removal is benign."
--
___________________________________________________________________________
mailto:stodden@in.tum.de