// </summary>
Constant TryReduceConstant (EmitContext ec, Constant e)
{
+ if (e is EmptyConstantCast)
+ return TryReduceConstant (ec, ((EmptyConstantCast) e).child);
+
if (e is SideEffectConstant) {
Constant r = TryReduceConstant (ec, ((SideEffectConstant) e).value);
return r == null ? null : new SideEffectConstant (r, e, r.Location);
if (expr == null)
return null;
- if (probe_type_expr.Type == TypeManager.void_type) {
- // TODO: Void is missing location (ProbeType.Location)
- Error_VoidInvalidInTheContext (Location);
- return null;
- }
-
if ((probe_type_expr.Type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
Report.Error (-244, loc, "The `{0}' operator cannot be applied to an operand of a static type",
OperatorName);
this.target_type = cast_type;
this.expr = expr;
this.loc = loc;
-
- if (target_type == TypeManager.system_void_expr)
- Error_VoidInvalidInTheContext (loc);
}
public Expression TargetType {
type = texpr.Type;
- if (type == TypeManager.void_type) {
- Error_VoidInvalidInTheContext (loc);
- return null;
+ if ((type.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
+ Report.Error (-244, loc, "The `default value' operator cannot be applied to an operand of a static type");
}
+ if (type.IsPointer)
+ return new NullLiteral (Location).ConvertImplicitly (type);
+
if (TypeManager.IsReferenceType (type)) {
return new EmptyConstantCast (new NullLiteral (Location), type);
return null;
}
- if (rc != null) {
- right = left;
- lc = rc;
- }
-
+ //
// The result is a constant with side-effect
- return new SideEffectConstant (lc, right, loc);
+ //
+ Constant side_effect = rc == null ?
+ new SideEffectConstant (lc, right, loc) :
+ new SideEffectConstant (rc, left, loc);
+
+ return ReducedExpression.Create (side_effect, this);
}
}
right.Emit (ec);
Type t = left.Type;
- bool is_unsigned = IsUnsigned (t) || IsFloat (t);
+ bool is_float = IsFloat (t);
+ bool is_unsigned = is_float || IsUnsigned (t);
switch (oper){
case Operator.Equality:
case Operator.LessThan:
if (on_true)
- if (is_unsigned)
+ if (is_unsigned && !is_float)
ig.Emit (OpCodes.Blt_Un, target);
else
ig.Emit (OpCodes.Blt, target);
case Operator.GreaterThan:
if (on_true)
- if (is_unsigned)
+ if (is_unsigned && !is_float)
ig.Emit (OpCodes.Bgt_Un, target);
else
ig.Emit (OpCodes.Bgt, target);
case Operator.LessThanOrEqual:
if (on_true)
- if (is_unsigned)
+ if (is_unsigned && !is_float)
ig.Emit (OpCodes.Ble_Un, target);
else
ig.Emit (OpCodes.Ble, target);
case Operator.GreaterThanOrEqual:
if (on_true)
- if (is_unsigned)
+ if (is_unsigned && !is_float)
ig.Emit (OpCodes.Bge_Un, target);
else
ig.Emit (OpCodes.Bge, target);
type = texpr.Type;
- if (type == TypeManager.void_type) {
- Error_VoidInvalidInTheContext (loc);
- return null;
- }
-
if (type.IsPointer) {
Report.Error (1919, loc, "Unsafe type `{0}' cannot be used in an object creation expression",
TypeManager.CSharpName (type));
Report.Error (622, loc, "Can only use array initializer expressions to assign to array types. Try using a new expression instead");
return false;
}
+
+ if (requested_base_type is VarExpr) {
+ Report.Error (820, loc, "An implicitly typed local variable declarator cannot use an array initializer");
+ return false;
+ }
StringBuilder array_qualifier = new StringBuilder (rank);
public bool ResolveBase (EmitContext ec)
{
+ if (eclass != ExprClass.Invalid)
+ return true;
+
eclass = ExprClass.Variable;
if (ec.TypeContainer.CurrentType != null)
if (TypeManager.IsEnumType (type_queried))
type_queried = TypeManager.GetEnumUnderlyingType (type_queried);
- if (type_queried == TypeManager.void_type) {
- Expression.Error_VoidInvalidInTheContext (loc);
- return null;
- }
-
int size_of = GetTypeSize (type_queried);
if (size_of > 0) {
return new IntConstant (size_of, loc);
loc = l;
}
- public Expression RemoveNullable ()
- {
- if (dim.EndsWith ("?")) {
- dim = dim.Substring (0, dim.Length - 1);
- if (dim.Length == 0)
- return left;
- }
-
- return this;
- }
-
protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
{
TypeExpr lexpr = left.ResolveAsTypeTerminal (ec, false);
return null;
Type ltype = lexpr.Type;
- if ((ltype == TypeManager.void_type) && (dim != "*")) {
- Error_VoidInvalidInTheContext (loc);
- return null;
- }
-
#if GMCS_SOURCE
if ((dim.Length > 0) && (dim [0] == '?')) {
TypeExpr nullable = new Nullable.NullableType (left, loc);
return null;
if (dim.Length != 0 && dim [0] == '[') {
- if (ltype == TypeManager.arg_iterator_type || ltype == TypeManager.typed_reference_type) {
+ if (TypeManager.IsSpecialType (ltype)) {
Report.Error (611, loc, "Array elements cannot be of type `{0}'", TypeManager.CSharpName (ltype));
return null;
}