Bug 325384 (MONO82717) - The compiler fails because of if/foreach scope bug
Summary: The compiler fails because of if/foreach scope bug
Status: RESOLVED WORKSFORME
Alias: MONO82717
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.2
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Raja R Harinath
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-06 16:43 UTC by Anders Rune Jensen
Modified: 2007-10-19 18:55 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:52:18 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".

Comment 1 Raja R Harinath 2007-09-18 12:20:30 UTC
Please provide a self-contained testcase.
Comment 2 Marek Safar 2007-10-05 20:45:49 UTC
I am unable to reproduce this with SVN HEAD.
Comment 3 Raja R Harinath 2007-10-19 18:55:21 UTC
cannot reproduce, and no simpler testcase