Bugzilla – Bug 321737
[ANONYMOUS METHODS] (FIXED) CS0136 not reported when re-declaring local variable as anonymous method parameter
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by gert.driesen@pandora.be 2006-08-07 11:27:25 MST ---- mcs and gmcs do not report CS0136 when a local variable is re-declared as a anonymous method parameter, and use the local variable in the anonymous method instead of the parameter. To reproduce, compile the following code snippet: using System; using System.Xml; public delegate void XmlWriterClosedEventHandler (XmlWriter writer); public class Test { public XmlWriterClosedEventHandler Closed; public void Whatever () { Console.WriteLine ("This should not execute!"); } static void Main () { Test t = new Test (); t.Closed += delegate (XmlWriter t) { t.Whatever (); }; t.Closed(null); } } Expected result: test.cs(16,25): error CS0136: A local variable named 't' cannot be declared in this scope because it would give a different meaning to 't', which is already used in a 'parent or current' scope to denote something else Actual result: Successful compilation, and when the resulting assembly is run the text "This should not execute!" is output, proving that mcs uses the outer variable t which is of type Test in the anonymous method instead of the parameter (XmlWriter) t. ---- Additional Comments From gert.driesen@pandora.be 2006-08-24 05:34:10 MST ---- *** https://bugzilla.novell.com/show_bug.cgi?id=MONO79153 has been marked as a duplicate of this bug. *** ---- Additional Comments From martin@ximian.com 2006-10-04 18:14:50 MST ---- Fixed in SVN. ---- Additional Comments From martin@ximian.com 2006-10-04 18:18:36 MST ---- Fixed in SVN. Unknown operating system unknown. Setting to default OS "Other".