Mono.CSharp.CompoundAssign.ResolveConversions C# (CSharp) Method

ResolveConversions() protected method

protected ResolveConversions ( ResolveContext ec ) : Expression
ec ResolveContext
return Expression
		protected override Expression ResolveConversions (ResolveContext ec)
		{
			//
			// LAMESPEC: Under dynamic context no target conversion is happening
			// This allows more natual dynamic behaviour but breaks compatibility
			// with static binding
			//
			if (target is RuntimeValueExpression)
				return this;

			TypeSpec target_type = target.Type;

			//
			// 1. the return type is implicitly convertible to the type of target
			//
			if (Convert.ImplicitConversionExists (ec, source, target_type)) {
				source = Convert.ImplicitConversion (ec, source, target_type, loc);
				return this;
			}

			//
			// Otherwise, if the selected operator is a predefined operator
			//
			Binary b = source as Binary;
			if (b == null && source is ReducedExpression)
				b = ((ReducedExpression) source).OriginalExpression as Binary;

			if (b != null) {
				//
				// 2a. the operator is a shift operator
				//
				// 2b. the return type is explicitly convertible to the type of x, and
				// y is implicitly convertible to the type of x
				//
				if ((b.Oper & Binary.Operator.ShiftMask) != 0 ||
					Convert.ImplicitConversionExists (ec, right, target_type)) {
					source = Convert.ExplicitConversion (ec, source, target_type, loc);
					return this;
				}
			}

			if (source.Type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
				Arguments arg = new Arguments (1);
				arg.Add (new Argument (source));
				return new SimpleAssign (target, new DynamicConversion (target_type, CSharpBinderFlags.ConvertExplicit, arg, loc), loc).Resolve (ec);
			}

			right.Error_ValueCannotBeConverted (ec, loc, target_type, false);
			return null;
		}