public static Constant CreateFromExpression(ResolveContext ec, Expression e) { ec.Report.Warning(458, 2, e.Location, "The result of the expression is always `null' of type `{0}'", TypeManager.CSharpName(e.Type)); return(ReducedExpression.Create(Create(e.Type, e.Location), e)); }
public static Constant CreateFromExpression(ResolveContext ec, Expression e) { ec.Report.Warning(458, 2, e.Location, "The result of the expression is always `null' of type `{0}'", e.Type.GetSignatureForError()); return(ReducedExpression.Create(Create(e.Type, e.Location), e)); }
public static Constant CreateFromExpression(ResolveContext rc, Expression e) { if (!rc.HasSet (ResolveContext.Options.ExpressionTreeConversion)) { rc.Report.Warning (458, 2, e.Location, "The result of the expression is always `null' of type `{0}'", e.Type.GetSignatureForError ()); } return ReducedExpression.Create (Create (e.Type, e.Location), e); }
// // CSC 2 has this behavior, it allows structs to be compared // with the null literal *outside* of a generics context and // inlines that as true or false. // Constant CreateNullConstant(ResolveContext ec, Expression expr) { // FIXME: Handle side effect constants Constant c = new BoolConstant(ec.BuiltinTypes, Oper == Operator.Inequality, loc); if ((Oper & Operator.EqualityMask) != 0) { ec.Report.Warning(472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'", TypeManager.CSharpName(expr.Type), c.GetValueAsLiteral()); } else { ec.Report.Warning(464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", TypeManager.CSharpName(expr.Type), c.GetValueAsLiteral()); } return(ReducedExpression.Create(c, this)); }
// // CSC 2 has this behavior, it allows structs to be compared // with the null literal *outside* of a generics context and // inlines that as true or false. // Expression CreateNullConstant(ResolveContext ec, Expression expr) { // FIXME: Handle side effect constants Constant c = new BoolConstant(Oper == Operator.Inequality, loc); if ((Oper & Operator.EqualityMask) != 0) { ec.Report.Warning(472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'", expr.GetSignatureForError(), c.AsString()); } else { ec.Report.Warning(464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'", expr.GetSignatureForError(), c.AsString()); } return(ReducedExpression.Create(c, this)); }
Expression ConvertExpression(ResolveContext ec) { // TODO: ImplicitConversionExists should take care of this if (left.eclass == ExprClass.MethodGroup) { return(null); } TypeSpec ltype = left.Type; // // If left is a nullable type and an implicit conversion exists from right to underlying type of left, // the result is underlying type of left // if (ltype.IsNullableType) { unwrap = Unwrap.Create(left, false); if (unwrap == null) { return(null); } // // Reduce (left ?? null) to left // if (right.IsNull) { return(ReducedExpression.Create(left, this)); } Expression conv; if (right.Type.IsNullableType) { conv = right.Type == ltype ? right : Convert.ImplicitNulableConversion(ec, right, ltype); if (conv != null) { right = conv; type = ltype; return(this); } } else { conv = Convert.ImplicitConversion(ec, right, unwrap.Type, loc); if (conv != null) { left = unwrap; ltype = left.Type; // // If right is a dynamic expression, the result type is dynamic // if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { type = right.Type; // Need to box underlying value type left = Convert.ImplicitBoxingConversion(left, ltype, type); return(this); } right = conv; type = ltype; return(this); } } } else if (TypeSpec.IsReferenceType(ltype)) { if (Convert.ImplicitConversionExists(ec, right, ltype)) { // // If right is a dynamic expression, the result type is dynamic // if (right.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { type = right.Type; return(this); } // // Reduce ("foo" ?? expr) to expression // Constant lc = left as Constant; if (lc != null && !lc.IsDefaultValue) { return(ReducedExpression.Create(lc, this, false)); } // // Reduce (left ?? null) to left OR (null-constant ?? right) to right // if (right.IsNull || lc != null) { // // Special case null ?? null // if (right.IsNull && ltype == right.Type) { return(null); } return(ReducedExpression.Create(lc != null ? right : left, this, false)); } right = Convert.ImplicitConversion(ec, right, ltype, loc); type = ltype; return(this); } } else { return(null); } TypeSpec rtype = right.Type; if (!Convert.ImplicitConversionExists(ec, unwrap ?? left, rtype) || right.eclass == ExprClass.MethodGroup) { return(null); } // // Reduce (null ?? right) to right // if (left.IsNull) { return(ReducedExpression.Create(right, this, false).Resolve(ec)); } left = Convert.ImplicitConversion(ec, unwrap ?? left, rtype, loc); type = rtype; return(this); }
Expression ConvertExpression(ResolveContext ec) { // TODO: ImplicitConversionExists should take care of this if (left.eclass == ExprClass.MethodGroup) { return(null); } Type ltype = left.Type; // // If left is a nullable type and an implicit conversion exists from right to underlying type of left, // the result is underlying type of left // if (TypeManager.IsNullableType(ltype)) { unwrap = Unwrap.Create(left, false); if (unwrap == null) { return(null); } if (Convert.ImplicitConversionExists(ec, right, unwrap.Type)) { left = unwrap; type = left.Type; right = Convert.ImplicitConversion(ec, right, type, loc); return(this); } } else if (TypeManager.IsReferenceType(ltype)) { if (Convert.ImplicitConversionExists(ec, right, ltype)) { // // Reduce (constant ?? expr) to constant // Constant lc = left as Constant; if (lc != null && !lc.IsDefaultValue) { return(new SideEffectConstant(lc, right, loc).Resolve(ec)); } // // Reduce (left ?? null) to left OR (null-constant ?? right) to right // if (right.IsNull || lc != null) { return(ReducedExpression.Create(lc != null ? right : left, this).Resolve(ec)); } right = Convert.ImplicitConversion(ec, right, ltype, loc); type = left.Type; return(this); } } else { return(null); } Type rtype = right.Type; if (!Convert.ImplicitConversionExists(ec, unwrap != null ? unwrap : left, rtype) || right.eclass == ExprClass.MethodGroup) { return(null); } // // Reduce (null ?? right) to right // if (left.IsNull) { return(ReducedExpression.Create(right, this).Resolve(ec)); } left = Convert.ImplicitConversion(ec, unwrap != null ? unwrap : left, rtype, loc); type = rtype; return(this); }