Bugzilla – Bug 325384
The compiler fails because of if/foreach scope bug
Last modified: 2007-10-19 18:55:21 UTC
---- Reported by anders@iola.dk 2007-09-06 09:43:18 MST ---- Description of Problem: The following code (although a little ugly) should compile: if (e.Event.Key == Gdk.Key.Escape) // cancel foreach (Gtk.Widget w in representation) if (w.Name == "new") w.Destroy(); // bye bye else if (e.Event.Key == Gdk.Key.Return) // ok foreach (Gtk.Widget w in representation) if (w.Name == "new") { string text = ((Gtk.Entry)w).Text; if (text != "") representation.Add(new Gtk.Button(text)); w.Destroy(); // bye bye } Steps to reproduce the problem: 1. Compile the above lines of code Actual Results: Compile error: A local variable named `w' cannot be declared in this scope because it would give a different meaning to `w', which is already used in a `parent' scope to denote something else(CS0136) Expected Results: Compiles fine since the second foreach w is in a different if block than the first foreach w. How often does this happen? Always Additional Information: Using Mono 1.2.3.1. Unknown operating system unknown. Setting to default OS "Other".
Please provide a self-contained testcase.
I am unable to reproduce this with SVN HEAD.
cannot reproduce, and no simpler testcase