[Mono-bugs] [Bug 355256] New: gmcs emits invalid code in some generic scenarios

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jan 22 07:03:36 EST 2008


           Summary: gmcs emits invalid code in some generic scenarios
           Product: Mono: Compilers
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: msafar at novell.com
        ReportedBy: jbevain at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

The following code compiled with gmcs generates invalid IL.

using System;
using System.Collections.Generic;

static class Enumerable {

        public static int Sum<TSource> (this IEnumerable<TSource> source,
Func<TSource, int> selector)
                return Sum<TSource, int> (source, (a, b) => a + selector (b));

        static TR Sum<TA, TR> (this IEnumerable<TA> source, Func<TR, TA, TR>
                if (source == null)
                        throw new ArgumentNullException ("source");
                if (selector == null)
                        throw new ArgumentNullException ("selector");

                TR total = default (TR);
                int counter = 0;
                foreach (var element in source) {
                        total = selector (total, element);

                if (counter == 0)
                        throw new InvalidOperationException ();

                return total;


class Repro {

        static void Main ()
                var sum = new [] {"1", "2", "3", "4",
                        "5", "6", "7"}.Sum ((Func<string, int>) null);
                Console.WriteLine (sum);

peverify output:

Microsoft (R) .NET Framework PE Verifier.  Version  2.0.50727.42
Copyright (c) Microsoft Corporation.  All rights reserved.

[IL] : Erreur : [C:\Tmp\test.exe : Enumerable::Sum[TSource]][offset 0x0000001D]
Arguments non reconnus pour le .ctor délégué.
[IL] : Erreur : [C:\Tmp\test.exe :
::<Sum>c__1[T1,T2,TResult]][offset 0x00000008][(unboxed) 'T1'
'TSource' attendu] Type inattendu sur la pile.
2 Errors Verifying test.exe

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