Bugzilla – Bug 310999
error in scope of local variable
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by duco@lorentz.xs4all.nl 2002-03-27 17:02:17 MST ---- Description of Problem: Checking the scope of a local variable hiding a class member variable is not correctly implemented. Steps to reproduce the problem: using System; class A { static int i = 42; public static void Main () { Console.WriteLine ( i ); int i = 37; } } Actual Results: When compiled using "mcs", this program prints "42". This is what a C++ programmer might expect, but it is wrong. Expected Results: The C# language reference specifies that the reference to "i" in the call to Console.WriteLine is to the local variable i declared in "Main". At the same time, it specifies that this reference is illegal, because it precedes its definition ("int i = 37"). In short: the expected result is a compilation error ("csc" reports error CS0136 on the example above). How often does this happen? Always ---- Additional Comments From miguel@ximian.com 2002-04-09 13:01:57 MST ---- I will be taking care of it. ---- Additional Comments From miguel@ximian.com 2002-05-08 21:15:04 MST ---- *** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO22724 *** Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>SuSE Linux 7.1</cf_op_sys_details> Unknown operating system unknown. Setting to default OS "Other". This bug was marked DUPLICATE in the database it was moved from. Changing resolution to "MOVED"