[Mono-bugs] [Bug 72448][Wis] New - [GMCS] NullReferenceException from gmcs when comparing type variable with interface contraint to null

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 10 Feb 2005 09:30:55 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by nazgul@omega.pl.

http://bugzilla.ximian.com/show_bug.cgi?id=72448

--- shadow/72448	2005-02-10 09:30:55.000000000 -0500
+++ shadow/72448.tmp.13720	2005-02-10 09:30:55.000000000 -0500
@@ -0,0 +1,123 @@
+Bug#: 72448
+Product: Mono: Compilers
+Version: 1.0
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: nazgul@omega.pl               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: [GMCS]  NullReferenceException from gmcs when comparing type variable with interface contraint to null
+
+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)