[Mono-bugs] [Bug 79025][Nor] New - CS0136 not reported when re-declaring local variable as anonymous method parameter

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Aug 7 11:27:26 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by gert.driesen at pandora.be.

http://bugzilla.ximian.com/show_bug.cgi?id=79025

--- shadow/79025	2006-08-07 11:27:25.000000000 -0400
+++ shadow/79025.tmp.10746	2006-08-07 11:27:25.000000000 -0400
@@ -0,0 +1,59 @@
+Bug#: 79025
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: gert.driesen at pandora.be               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: CS0136 not reported when re-declaring local variable as anonymous method parameter
+
+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.


More information about the mono-bugs mailing list