[Mono-bugs] [Bug 41776][Nor] New - Definite assignment problem

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Wed, 23 Apr 2003 05:47:48 -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 staerk@inf.ethz.ch.

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

--- shadow/41776	Wed Apr 23 05:47:48 2003
+++ shadow/41776.tmp.27247	Wed Apr 23 05:47:48 2003
@@ -0,0 +1,50 @@
+Bug#: 41776
+Product: Mono/MCS
+Version: unspecified
+OS: Red Hat 7.2
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: staerk@inf.ethz.ch               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Definite assignment problem
+
+The following program is rejected by MCS but not
+but Microsoft's .NET compiler. Since the
+`return i' statement is not reachable, the 
+variable `i' should be considered as definitely
+assigned there. See 12.3.3.1 "General rules for statements"
+in the Ecma C# Standard.
+
+class Test3 {
+  static int F() {
+    int i;
+    if (true)
+      return 0;
+    else
+      return i;
+  }
+
+  public static void Main() {
+    System.Console.WriteLine(F());
+  }
+}
+
+// Mono (Redhat 7.2)
+// > mcs Test3.cs
+// Test3.cs(7) error CS0165: Use of unassigned local variable `i'
+// Compilation failed: 1 error(s), 0 warnings
+
+// Microsoft .NET
+// > csc Test3.cs
+// Test3.cs(7,7): warning CS0162: Unreachable code detected
+//
+// > Test3.exe
+// 0