[Mono-bugs] [Bug 22646] New - error in scope of local variable

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
27 Mar 2002 22:02:17 -0000


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 duco@lorentz.xs4all.nl.

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

--- shadow/22646	Wed Mar 27 17:02:17 2002
+++ shadow/22646.tmp.19826	Wed Mar 27 17:02:17 2002
@@ -0,0 +1,49 @@
+Bug#: 22646
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: SuSE Linux 7.1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: duco@lorentz.xs4all.nl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: error in scope of local variable
+
+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