[Mono-bugs] [Bug 76128][Min] New - "this" is regarded as never be compatible with generic type parameter

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Sep 16 16:48:38 EDT 2005


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 atsushi at ximian.com.

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

--- shadow/76128	2005-09-16 16:48:38.000000000 -0400
+++ shadow/76128.tmp.27554	2005-09-16 16:48:38.000000000 -0400
@@ -0,0 +1,94 @@
+Bug#: 76128
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: atsushi at ximian.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: "this" is regarded as never be compatible with generic type parameter
+
+The example below fails to compile because "this" is regarded as
+incompatible with T. However T might be Test so it should pass.
+
+using System.Collections.Generic;
+
+class Test
+{
+        public IEnumerable<T> Foo <T> (IEnumerator<object> e)
+        {
+                List<T> l = new List<T> ();
+                if (this is T)
+                        l.Add ((T) this);
+                return l;
+        }
+}
+
+Actual Results:
+
+$ !gmcs
+gmcs generic-t.cs
+generic-t.cs(8,12): warning CS0184: The given expression is never of the
+provided (`T') type
+generic-t.cs(9,12): error CS0030: Cannot convert type 'Test' to 'T'
+Compilation failed: 1 error(s), 1 warnings
+
+Expected Results:
+
+No CS0030 error.
+
+How often does this happen? 
+
+consistently.
+
+Additional Information:
+
+MS csc also fails to compile it (the same CS0030 error).
+
+
+Here are the corresponding sections from C# 2.1 spec. I think this "T" is
+an open type.
+
+--------
+14.9.10 is operator
+The is operator is used to dynamically check if the run-time type of an
+object is compatible with a given
+type. The result of the operation e is T, where e is an expression and T is
+a type, is a Boolean value
+indicating whether e can successfully be converted to type T by a reference
+conversion, a boxing conversion,
+or an unboxing conversion. The operation is evaluated as follows:
+• If the compile-time type of e is the same as T, or if an implicit
+reference conversion (§13.1.4) or boxing
+conversion (§13.1.5) exists from the compile-time type of e to T:
+o If e is of a reference type, the result of the operation is equivalent to
+evaluating e != null.
+o If e is of a value type, the result of the operation is true.
+• Otherwise, if an explicit reference conversion (§13.2.3) or unboxing
+conversion (§13.2.4) exists from
+the compile-time type of e to T, a dynamic type check is performed:
+o If the value of e is null, the result is false.
+o Otherwise, let R be the run-time type of the instance referenced by e. If
+R and T are the same type, if
+R is a reference type and an implicit reference conversion from R to T
+exists, or if R is a value type
+and T is an interface type that is implemented by R, the result is true.
+o Otherwise, the result is false.
+• Otherwise, if the compile-time type of e or T is an open type (§25.5.2),
+a dynamic type check is
+performed.
+
+--------
+25.5.2 Open and closed types
+All types can be classified as open types or closed types. An open type is
+a type that involves type
+parameters. More specifically:
+• A type parameter defines an open type.


More information about the mono-bugs mailing list