Bug 416110

Summary: struct constraint should result in default ctor and ValueType base type constraint
Product: [Mono] Mono: Compilers Reporter: Gert Driesen <gert.driesen>
Component: C#Assignee: Marek Safar <msafar>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None CC: alp, atsushieno
Version: SVN   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Gert Driesen 2008-08-10 15:52:38 UTC
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.
Comment 1 Marek Safar 2008-09-19 15:11:32 UTC
*** Bug 413414 has been marked as a duplicate of this bug. ***
Comment 2 Marek Safar 2008-09-19 15:13:56 UTC
*** Bug 324740 has been marked as a duplicate of this bug. ***
Comment 3 Marek Safar 2008-09-19 15:16:16 UTC
*** Bug 324741 has been marked as a duplicate of this bug. ***
Comment 4 Marek Safar 2008-09-19 15:17:21 UTC
*** Bug 324072 has been marked as a duplicate of this bug. ***
Comment 5 Marek Safar 2008-09-19 15:18:45 UTC
*** Bug 324703 has been marked as a duplicate of this bug. ***
Comment 6 Marek Safar 2008-09-19 15:22:47 UTC
Fixed in SVN.