+2009-10-27 Marek Safar <marek.safar@gmail.com>
+
+ * constant.cs, nullable.cs: Create nullable-null as LiftedNull
+ constant.
+
+ * class.cs: Allow nullable binary user operators.
+
2009-10-26 Marek Safar <marek.safar@gmail.com>
* expression.cs: Move binary expression optimization at the end of
}
}
- } else {
+ } else if (!TypeManager.IsEqual (first_arg_type_unwrap, declaring_type)) {
// Checks for Binary operators
-
- if (first_arg_type != declaring_type &&
- Parameters.Types [1] != declaring_type){
- Report.Error (
- 563, Location,
- "One of the parameters of a binary operator must " +
- "be the containing type");
+
+ var second_arg_type = ParameterTypes [1];
+ if (TypeManager.IsNullableType (second_arg_type))
+ second_arg_type = TypeManager.TypeToCoreType (TypeManager.GetTypeArguments (second_arg_type) [0]);
+
+ if (!TypeManager.IsEqual (second_arg_type, declaring_type)) {
+ Report.Error (563, Location,
+ "One of the parameters of a binary operator must be the containing type");
return false;
}
}
Type real_type = TypeManager.GetEnumUnderlyingType (t);
return new EnumConstant (CreateConstant (real_type, v, loc), t);
}
- if (v == null && !TypeManager.IsValueType (t))
- return new EmptyConstantCast (new NullLiteral (loc), t);
+ if (v == null) {
+ if (TypeManager.IsNullableType (t))
+ return Nullable.LiftedNull.Create (t, loc);
+
+ if (TypeManager.IsReferenceType (t))
+ return new NullConstant (t, loc);
+ }
throw new InternalErrorException ("Constant value `{0}' has unexpected underlying type `{1}'",
v, TypeManager.CSharpName (t));
//
// Represents null literal lifted to nullable type
//
- public class LiftedNull : EmptyConstantCast, IMemoryLocation
+ public class LiftedNull : NullConstant, IMemoryLocation
{
private LiftedNull (Type nullable_type, Location loc)
- : base (new NullLiteral (loc), nullable_type)
+ : base (nullable_type, loc)
{
eclass = ExprClass.Value;
}
return ReducedExpression.Create (Create (e.Type, e.Location), e);
}
- public override Expression CreateExpressionTree (ResolveContext ec)
- {
- Arguments args = new Arguments (2);
- args.Add (new Argument (this));
- args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
-
- return CreateExpressionFactoryCall (ec, "Constant", args);
- }
-
public override void Emit (EmitContext ec)
{
// TODO: generate less temporary variables