[Mono-bugs] [Bug 429264] [gmcs] Invalid IL generated with nested iterators

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Sep 26 11:13:37 EDT 2008


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

User jpryor at novell.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=429264#c3


Jonathan Pryor <jpryor at novell.com> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
             Status|RESOLVED                                        |REOPENED
         Resolution|FIXED                                           |




--- Comment #3 from Jonathan Pryor <jpryor at novell.com>  2008-09-26 09:13:37 MDT ---
Reopening; same symptoms (TypeLoadException at runtime, `pedump --verify all`
shows invalid IL errors), same basic idea (iterator madness!), different
source:

  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;

  static class Extensions {
    public static IEnumerable<TResult> Parse<TSource, 
          TAccumulate, TResult> (
        this IEnumerable<TSource> self, 
        TAccumulate seed, 
        Action<TAccumulate, TSource> accumulate,
        Func<TAccumulate, TResult> resultSelector, 
        params Func<TSource, bool>[] levels)
    {
      return CreateParseIterator (self, seed, accumulate, 
        resultSelector, levels);
    }

    private static IEnumerable<TResult> CreateParseIterator<TSource, 
          TAccumulate, TResult> (
        IEnumerable<TSource> self, 
        TAccumulate seed, 
        Action<TAccumulate, TSource> accumulate,
        Func<TAccumulate, TResult> resultSelector, 
        params Func<TSource, bool>[] levels)
    {
      bool have_data = false;
      int level = -1;
      foreach (var s in self) {
        var nl = levels
          .Select ((l, i) => l (s) ? i : -1)
          .Where (n => n >= 0);
        int next_level = nl.Count () > 0 ? nl.Min () : -1;
        if (next_level == level && level >= 0) {
          accumulate (seed, s);
          have_data = true;
        }
        else if (next_level >= 0) {
          if (have_data)
            yield return resultSelector (seed);
          level = next_level;
          accumulate (seed, s);
        }
        else {
          if (have_data)
            yield return resultSelector (seed);
          level = -1;
          have_data = false;
        }
      }
      if (have_data)
        yield return resultSelector (seed);
    }
  }

  class Test {
    public static void Main ()
    {
      string[] s = "1 2 3 4".Parse (new StringBuilder (),
        (buf, c) => buf.Append (c),
        buf => {var r = buf.ToString (); buf.Length = 0; return r;},
        c => !char.IsWhiteSpace (c)).ToArray ();
    }
  }


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


More information about the mono-bugs mailing list