Bug 317541 (MONO74114) - [GMCS]Cannot call new on a generic struct type without new constraint
Summary: [GMCS]Cannot call new on a generic struct type without new constraint
Status: RESOLVED FIXED
Alias: MONO74114
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: 1.1
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Martin Baulig
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-26 19:26 UTC by Marcus Cuda
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 19:11:38 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".