Bugzilla – Bug 317153
[GMCS] NullReferenceException from gmcs when comparing type variable with interface contraint to null
Last modified: 2007-09-15 21:24:23 UTC
---- Reported by nazgul@omega.pl 2005-02-10 09:30:55 MST ---- Please fill in this template when reporting a bug, unless you know what you are doing. Description of Problem: I got exception from gmcs for code, which work on MS.NET Beta1 Steps to reproduce the problem: 1. Try to compile this program: using System.Collections.Generic; // comment this line to see another bug in gmcs (unrelated) interface IB { bool foo (); } class B : IB { public bool foo () { return true; } } interface Filter <T> where T : IB { T Is (IB x); } struct K : IB { public bool foo () { return false; } } class MyFilter : Filter <K> { public K Is (IB x) { return new K(); } } class MyBFilter : Filter <B> { public B Is (IB x) { return new B(); } } class M { static List<T> foo1 <T> (Filter <T> x) where T : IB { List <T> result = new List <T>(); T maybe = x.Is (new B()); if (maybe != null) result.Add (maybe); return result; } static void Main () { MyFilter m = new MyFilter (); System.Console.WriteLine (foo1 <K> (m).Count); MyBFilter mb = new MyBFilter (); System.Console.WriteLine (foo1 <B> (mb).Count); } } Actual Results: Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object in <0x000fc> Mono.CSharp.GenericConstraints:get_IsReferenceType () in <0x000a0> Mono.CSharp.Convert:ImplicitTypeParameterConversion (Mono.CSharp.EmitContext,Mono.CSharp.Expression,System.Type) in <0x00045> Mono.CSharp.Convert:ImplicitReferenceConversionExists (Mono.CSharp.EmitContext,Mono.CSharp.Expression,System.Type) in <0x003c3> Mono.CSharp.Convert:ImplicitStandardConversionExists (Mono.CSharp.EmitContext,Mono.CSharp.Expression,System.Type) in <0x00173> Mono.CSharp.ConstructedType:CheckConstraint (Mono.CSharp.EmitContext,System.Type,Mono.CSharp.Expression,System.Type) in <0x00368> Mono.CSharp.ConstructedType:CheckConstraints (Mono.CSharp.EmitContext,int) in <0x0001b> Mono.CSharp.ConstructedType:CheckConstraints (Mono.CSharp.EmitContext) in <0x00026> Mono.CSharp.ConstructedType:ResolveAsTypeTerminal (Mono.CSharp.EmitContext) in <0x00021> Mono.CSharp.Parameter:Resolve (Mono.CSharp.EmitContext,Mono.CSharp.Location) in <0x000ef> Mono.CSharp.Parameters:ComputeParameterTypes (Mono.CSharp.EmitContext) in <0x00033> Mono.CSharp.Parameters:GetParameterInfo (Mono.CSharp.EmitContext) in <0x00067> Mono.CSharp.MethodCore:DoDefineParameters () in <0x0003a> Mono.CSharp.MethodCore:CheckBase () in <0x000ac> Mono.CSharp.Method:Define () in <0x00077> MemberCoreArrayList:DefineContainerMembers () in <0x00010> MethodArrayList:DefineContainerMembers () in <0x00014> Mono.CSharp.TypeContainer:DefineContainerMembers (Mono.CSharp.TypeContainer/MemberCoreArrayList) in <0x004ef> Mono.CSharp.TypeContainer:DoDefineMembers () in <0x0002b> Mono.CSharp.TypeContainer:DefineMembers (Mono.CSharp.TypeContainer) in <0x00284> Mono.CSharp.RootContext:PopulateTypes () in <0x00b46> Mono.CSharp.Driver:MainDriver (string[]) in <0x0001f> Mono.CSharp.Driver:Main (string[]) Expected Results: Compilation succeeded and 1 1 when program is run How often does this happen? Always Additional Information: (try commenting IB interface definition to see some other crash, which happens after error message is given - probably it should be filed as another bug) ---- Additional Comments From martin@ximian.com 2005-02-21 20:01:58 MST ---- I'm almost done with a fix, but too tired to finish it tonight. Will fix it tomorrow morning. ---- Additional Comments From martin@ximian.com 2005-02-22 15:35:59 MST ---- Fixed in SVN (both issues). Unknown bug field "cf_op_sys_details" encountered while moving bug <cf_op_sys_details>Mandrake Linux 10.1</cf_op_sys_details> Unknown bug field "cf_version_details" encountered while moving bug <cf_version_details>mono from svn (about 2 Feb)</cf_version_details> Unknown operating system unknown. Setting to default OS "Other".