Bug 321737 (MONO79025) - [ANONYMOUS METHODS] (FIXED) CS0136 not reported when re-declaring local variable as anonymous method parameter
Summary: [ANONYMOUS METHODS] (FIXED) CS0136 not reported when re-declaring local varia...
Status: RESOLVED FIXED
Alias: MONO79025
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-07 18:27 UTC by Gert Driesen
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 20:05:45 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".