Bugzilla – Bug 317541
[GMCS]Cannot call new on a generic struct type without new constraint
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by marcus@cuda.org 2005-03-26 12:26:44 MST ---- Description of Problem: Note: This is marked as resolved in https://bugzilla.novell.com/show_bug.cgi?id=MONO68326, the problem still exists in mono 1.1.5 You cannot call new on a generic stuct type (that is a generic type with a struct constaint) without specifing a new constraint. See code below. Since a struct always has a default constructor, the new constraint is not needed. MS .NET 2.0 (Feb CTP) does not require the new constraint and will not compile with it (Error: The 'new()' constraint cannot be used with the 'struct' constraint). Steps to reproduce the problem: Try to compile this code class Test<T> where T: struct{ public Test(){ T s = new T(); } } Actual Results: using mono 1.1.5 test.cs(3) error CS0304: Cannot create an instance of the variable type 'T' because it doesn't have the new() constraint Expected Results: should compile fine How often does this happen? Additional Information: ---- Additional Comments From martin@ximian.com 2005-04-29 08:33:20 MST ---- Fixed in SVN. Unknown operating system SUSE 9.2. Setting to default OS "Other".