[Mono-bugs] [Bug 49904][Nor] New - Error CS0136 for compiling program -- scope issue
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 20 Oct 2003 17:58:01 -0400 (EDT)
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 baskmau@hotmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=49904
--- shadow/49904 2003-10-20 17:58:01.000000000 -0400
+++ shadow/49904.tmp.995 2003-10-20 17:58:01.000000000 -0400
@@ -0,0 +1,91 @@
+Bug#: 49904
+Product: Mono/MCS
+Version: unspecified
+OS:
+OS Details: debian gnu/linux woody 2.4.18
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: baskmau@hotmail.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Error CS0136 for compiling program -- scope issue
+
+Description of Problem:
+
+Scopes seem to work differently in Java and C# per mcs and javac -- not
+sure if this is the case:
+
+Compiling C# program with 0.26 mcs gives:
+
+class Scope
+{
+ bool condition;
+
+ Scope()
+ {
+ condition = true;
+
+ if ( condition )
+ {
+ int inner = 0;
+ Console.WriteLine( " .. inside if block .. " );
+ }
+
+ int inner = 0;
+ Console.WriteLine( " .. top level scope .. " );
+ }
+
+ public static void Main()
+ {
+ Scope test = new Scope();
+ Console.WriteLine( " .. fini scope test .. " );
+ }
+}
+
+gives the following error message:
+
+Scope.cs(15) error CS0136: A local variable named `inner' cannot be
+declared in this scope since it would give a different meaning to `inner',
+which is already used in a `child' scope to denote something else
+Compilation failed: 1 error(s), 0 warnings
+
+Expected Results:
+Additional Information:
+
+The corresponding Java program compiles and runs:
+class Scope
+{
+ boolean condition;
+
+ Scope()
+ {
+ condition = true;
+
+ if ( condition )
+ {
+ int inner = 0;
+ System.out.println( " .. inside if block .. " );
+ }
+
+ int inner = 0;
+ System.out.println( " .. top level scope .. " );
+ }
+
+ public static void main( String[] args )
+ {
+ Scope test = new Scope();
+ System.out.println( " .. fini scope test .. " );
+ }
+}
+~/j2sdk142/bin/java Scope
+ .. inside if block ..
+ .. top level scope ..
+ .. fini scope test ..
+
+I thought scopes would work similarly in this case: