Bugzilla – Bug 312222
Definite assignment errors
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by staerk@inf.ethz.ch 2003-04-23 10:44:08 MST ---- Here are some programs where Mono's MCS and Microsoft's CSC do not agree on definite assignement (see also 13.3.3 "Precise rules for determining definite assignment" in the Ecma C# standard). ------------------------------------------------------------------------ using System; class Test14 { static void F(bool b, int i) { int x; if (b && (x = i) >= 0) // OK: 'x' definitely assigned Console.WriteLine(x); else // Error: 'x' not definitely assigned Console.WriteLine(x); } public static void Main() { F(true,5); F(false,7); } } // Mono (mcs 0.23 Redhat 7.2) // > mcs Test14.cs // Compilation succeeded // qed> mono Test14.exe // 5 // 0 // Microsoft .NET // > csc Test14.cs // Test14.cs(11,25): error CS0165: Use of unassigned local variable 'x' ------------------------------------------------------------------------ using System; class Test15 { static void F(bool b, int i) { int x; if (b || (x = i) >= 0) // Error: 'x' not definitely assigned Console.WriteLine(x); else // OK: 'x' definitely assigned Console.WriteLine(x); } public static void Main() { F(true,5); F(false,7); } } // Mono (mcs 0.23 Redhat 7.2) // > mcs Test15.cs // Compilation succeeded // qed> mono Test15.exe // 0 // 7 // Microsoft .NET // > csc Test14.cs // Test14.cs(11,25): error CS0165: Use of unassigned local variable 'x' ------------------------------------------------------------------------ using System; class Test13 { static void F(int i) { int x; while (true) { if (i < 7) { x = 3; break; } } // OK: 'x' definitely assigned Console.WriteLine(x); } public static void Main() { F(4); } } // Mono (mcs 0.23 Redhat 7.2) // > mcs Test13.cs // Test13.cs(13) error CS0165: Use of unassigned local variable `x' // Compilation failed: 1 error(s), 0 warnings // Microsoft .NET // > csc Test13.cs // > Test13.exe // 3 ------------------------------------------------------------------------ using System; class Test5 { static void F(bool b) { int x; while (b?true:true); // OK: 'x' definitely assigned Console.WriteLine(x); } public static void Main() { F(true); } } // Mono (mcs 0.23 Redhat 7.2) // > mcs Test5.cs // Test5.cs(8) error CS0165: Use of unassigned local variable `x' // Compilation failed: 1 error(s), 0 warnings // Microsoft .NET // > csc Test5.cs // > Test5.exe ------------------------------------------------------------------------ ---- Additional Comments From martin@ximian.com 2003-05-18 17:18:38 MST ---- Setting severity to one week since this'll probably require some larger changes in the flow code. This means that it may take a long time to get this bug fixed .... ---- Additional Comments From martin@ximian.com 2004-04-27 23:14:34 MST ---- See https://bugzilla.novell.com/show_bug.cgi?id=MONO57747. *** This bug has been marked as a duplicate of https://bugzilla.novell.com/show_bug.cgi?id=MONO57747 *** 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"