+2007-04-11 Martin Baulig <martin@ximian.com>
+
+ * expression.cs (As): Add support for nullable types; fixes #79371.
+
2007-04-11 Martin Baulig <martin@ximian.com>
* doc.cs (DocUtil.GetSignatureForDoc): Don't crash if
if (do_isinst)
ig.Emit (OpCodes.Isinst, probe_type_expr.Type);
+
+#if GMCS_SOURCE
+ if (TypeManager.IsNullableType (type))
+ ig.Emit (OpCodes.Unbox_Any, type);
+#endif
}
static void Error_CannotConvertType (Type source, Type target, Location loc)
eclass = ExprClass.Value;
Type etype = expr.Type;
- if (type.IsValueType) {
+ if (type.IsValueType && !TypeManager.IsNullableType (type)) {
Report.Error (77, loc, "The as operator must be used with a reference type (`" +
TypeManager.CSharpName (type) + "' is a value type)");
return null;
}
}
#endif
-
+
Expression e = Convert.ImplicitConversion (ec, expr, type, loc);
if (e != null){
expr = e;
--- /dev/null
+using System;
+
+public class NullableInt
+{
+ public static void Main()
+ {
+ object x = null;
+
+ int? y = x as int?; /* Causes CS0077 */
+
+ Console.WriteLine("y: '{0}'", y);
+ Console.WriteLine("y.HasValue: '{0}'", y.HasValue);
+ }
+}