Expression source_type_expr;
if (source_type.IsNullableType) {
- // No implicit conversion S? -> T for non-reference types
- if (implicitOnly && !TypeSpec.IsReferenceType (target_type) && !target_type.IsNullableType)
- return null;
-
- source_type_expr = Nullable.Unwrap.Create (source);
- source_type = source_type_expr.Type;
+ // No unwrapping conversion S? -> T for non-reference types
+ if (implicitOnly && !TypeSpec.IsReferenceType (target_type) && !target_type.IsNullableType) {
+ source_type_expr = source;
+ } else {
+ source_type_expr = Nullable.Unwrap.Create (source);
+ source_type = source_type_expr.Type;
+ }
} else {
source_type_expr = source;
}
var c = source as Constant;
if (c != null) {
source = c.TryReduce (ec, s_x);
- } else {
+ if (source == null)
+ c = null;
+ }
+
+ if (c == null) {
source = implicitOnly ?
ImplicitConversionStandard (ec, source_type_expr, s_x, loc) :
ExplicitConversionStandard (ec, source_type_expr, s_x, loc);
public UserCast (MethodSpec method, Expression source, Location l)
{
+ if (source == null)
+ throw new ArgumentNullException ("source");
+
this.method = method;
this.source = source;
type = method.ReturnType;
--- /dev/null
+struct C<T>
+{
+ public static implicit operator C<T> (T value)
+ {
+ return default (C<T>);
+ }
+}
+
+class C
+{
+ public static void Main ()
+ {
+ C<bool?> p = true;
+ C<int?> p2 = (int?)null;
+ }
+}
</method>\r
</type>\r
</test>\r
+ <test name="gtest-570.cs">\r
+ <type name="C">\r
+ <method name="Void Main()" attrs="150">\r
+ <size>29</size>\r
+ </method>\r
+ <method name="Void .ctor()" attrs="6278">\r
+ <size>7</size>\r
+ </method>\r
+ </type>\r
+ <type name="C`1[T]">\r
+ <method name="C`1 op_Implicit(T)" attrs="2198">\r
+ <size>18</size>\r
+ </method>\r
+ </type>\r
+ </test>\r
<test name="gtest-anontype-01.cs">\r
<type name="Test">\r
<method name="Int32 Main()" attrs="145">\r