[Mono-bugs] [Bug 431746] New: IEnumerable non-conforming to ECMA-334 specification

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Oct 2 16:03:45 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=431746


           Summary: IEnumerable non-conforming to ECMA-334 specification
           Product: Mono: Compilers
           Version: 1.9
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: ryder.lewis at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User


Description of Problem:

C# compiler produces an application that does not behave as expected. The
following is from ECMA-334, third revision... "Properly implemented enumerables
generate independent enumerators each time their GetEnumerator method is
called. Assuming the internal state of the enumerable has not changed between
two calls to GetEnumerator, the two enumerators returned should produce the
same set of values in the same order. This should hold even if the lifetimes of
the enumerators overlap as in the following code sample:"

-----
using System;
using System.Collections.Generic;

class Test
{
   static IEnumerable<int> FromTo(int from, int to) {
      while (from <= to) yield return from++;
   }

   static void Main() {
      IEnumerable<int> e = FromTo(1, 10);

      foreach (int x in e) {
         foreach (int y in e) {
            Console.Write("{0,3} ", x * y);
         }
         Console.WriteLine();
      }
   }
}
------


Steps to reproduce the problem:
1. Compile and run above code sample

Actual Results:

  2   3   4   5   6   7   8   9  10
  6   8  10  12  14  16  18  20
 12  15  18  21  24  27  30
 20  24  28  32  36  40
 30  35  40  45  50
 42  48  54  60
 56  63  70
 72  80
 90

Expected Results:

  1   2   3   4   5   6   7   8   9  10
  2   4   6   8  10  12  14  16  18  20
  3   6   9  12  15  18  21  24  27  30
  4   8  12  16  20  24  28  32  36  40
  5  10  15  20  25  30  35  40  45  50
  6  12  18  24  30  36  42  48  54  60
  7  14  21  28  35  42  49  56  63  70
  8  16  24  32  40  48  56  64  72  80
  9  18  27  36  45  54  63  72  81  90
 10  20  30  40  50  60  70  80  90 100

How often does this happen? 

Every time.

Additional Information:

Same output occurs with gmcs version 1.1.12.1 and 1.9.1.0. I do not have access
to Microsoft's C# compiler to see if the same thing happens.  However, the
expected output can be reached by introducing a local variable in FromTo()... 

   static IEnumerable<int> FromTo(int from, int to) {
      int i = from;
      while (i <= to) yield return i++;
   }


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list