Bug 320300 (MONO77522) - [GENERICS] Runtime doesn't check constraints
Summary: [GENERICS] Runtime doesn't check constraints
Status: RESOLVED FIXED
Alias: MONO77522
Product: Mono: Runtime
Classification: Mono
Component: generics (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Major
Target Milestone: V2_0
Assignee: Rodrigo Kumpera
QA Contact: Rodrigo Kumpera
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-02-10 11:24 UTC by Martin Baulig
Modified: 2010-11-27 19:05 UTC (History)
1 user (show)

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:47:54 UTC


---- Reported by martin@ximian.com 2006-02-10 04:24:55 MST ----

Our runtime doesn't check the constraints when instantiating a generic type.

For instance in the following example, Type.MakeGenericType() must throw an
ArgumentException.

=====
using System;

public class Foo<T>
        where T : struct
{ }

class X
{
        static void Main ()
        {
                Type t = typeof (Foo<>);
                t.MakeGenericType (typeof (X));
        }
}
=====

On Windows, this is throwing at runtime:

=====
martin@mordor ~
$ csc N.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.7
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.


martin@mordor ~
$ ./N.exe

Unhandled Exception: System.ArgumentException: GenericArguments[0], 'X', on
'Foo`1[T]' violates the constraint of type 'T'. --->
System.TypeLoadException: GenericArguments[0], 'X', on 'Foo`1[T]' violates
the constraint of type parameter 'T'.
   at System.RuntimeTypeHandle._Instantiate(RuntimeTypeHandle[] inst)
   at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle[] inst)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   --- End of inner exception stack trace ---
   at System.RuntimeType.ValidateGenericArguments(MemberInfo definition,
Type[] genericArguments, Exception e)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at X.Main()

martin@mordor ~
===============



---- Additional Comments From miguel@ximian.com 2006-10-07 11:37:22 MST ----

Moving to runtime


Unknown operating system unknown. Setting to default OS "Other".

Comment 1 Konstantin Geist 2010-05-24 16:30:01 UTC
Checked 2.6.4, no progress after almost 4.5 years.

Any plans to fix?
Comment 2 Rodrigo Kumpera 2010-11-27 19:05:04 UTC
Done.