[Mono-bugs] [Bug 75645][Nor] New - gmcs miscompiles IEnumerator or yield

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Wed Jul 27 03:53:06 EDT 2005


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 ken-bugzilla at friislarsen.net.

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

--- shadow/75645	2005-07-27 03:53:06.000000000 -0400
+++ shadow/75645.tmp.20081	2005-07-27 03:53:06.000000000 -0400
@@ -0,0 +1,68 @@
+Bug#: 75645
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: Ubuntu breezy
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: ken-bugzilla at friislarsen.net               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: gmcs miscompiles IEnumerator or yield
+
+Given the following program:
+
+---
+// Example that GMCS miscompiles
+using System;
+using System.Collections;
+using System.IO;
+
+class MainClass {
+    public static void Main(string[] args) {
+        TextReader r = new StringReader("foobar");
+        Tokenizer toks = new Tokenizer(r);
+        int chars = 0;
+        foreach(int n in toks) {
+            chars += n;
+        }
+        Console.WriteLine("Number of characters = {0}", chars);
+    }
+}
+
+class Tokenizer : IEnumerable {
+    private TextReader reader;
+    
+    public Tokenizer(TextReader r) {
+        this.reader = r;
+    }
+    
+    public IEnumerator GetEnumerator() {
+        while ( reader.Peek() != -1 ) {
+            reader.Read(); yield return 1;
+        }
+    }    
+}
+---
+
+gmcs compiles the program without problems.  But I run the resulting
+executable I get an unhandled exception:
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+in <0x0004b> Tokenizer+<GetEnumerator>__0:MoveNext ()
+in <0x000c9> MainClass:Main (System.String[] args)
+
+mcs compiles the program without problems and the resulting executables
+prints "Numbers of characters = 6" as expected.
+
+Additional Information:
+gmcs comes from the mono-gmcs package in Ubuntu Breezy.
+gmcs --version says "Mono C# compiler version 1.1.5.0" but the mono-gmcs
+package says "Version: 1.1.8.2-1ubuntu1"


More information about the mono-bugs mailing list