[Mono-bugs] [Bug 416110] New: struct constraint should result in default ctor and ValueType base type constraint

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sun Aug 10 11:52:39 EDT 2008


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

User gert.driesen at pandora.be added comment
https://bugzilla.novell.com/show_bug.cgi?id=416110#c1

           Summary: struct constraint should result in default ctor and
                    ValueType base type constraint
           Product: Mono: Compilers
           Version: SVN
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: gert.driesen at pandora.be
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


To match csc, using struct as constraint for a generic type argument should
implicitly also set the DefaultConstructorConstraint and set System.ValueType
as type constraint.

To reproduce, compile and run the following code:

using System;
using System.Reflection;

class Program
{
        static int Main ()
        {
                Type type = typeof (Foo<>);
                Type [] gargs = type.GetGenericArguments ();
                if (gargs == null || gargs.Length != 1) {
                        Console.WriteLine ("#1");
                        return 1;
                }

                Type garg = gargs [0];
                Type [] csts = garg.GetGenericParameterConstraints ();

                if (garg.Name != "T") {
                        Console.WriteLine ("#2: " + garg.Name);
                        return 2;
                }
                if (garg.GenericParameterAttributes !=
(GenericParameterAttributes.DefaultConstructorConstraint |
GenericParameterAttributes.NotNullableValueTypeConstraint)) {
                        Console.WriteLine ("#3: " +
garg.GenericParameterAttributes);
                        return 3;
                }
                if (csts == null || csts.Length != 1) {
                        Console.WriteLine ("#4");
                        return 4;
                }
                if (csts [0] != typeof (ValueType)) {
                        Console.WriteLine ("#5: " + csts [0].FullName);
                        return 5;
                }

                return 0;
        }
}

struct Foo<T> where T : struct
{
}

Actual result:

#3: NotNullableValueTypeConstraint
and exit code 3.

Expected result:

No output and exit code 0.


-- 
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