Mono.CSharp.Return.DoResolve C# (CSharp) Method

DoResolve() protected method

protected DoResolve ( BlockContext ec ) : bool
ec BlockContext
return bool
		protected override bool DoResolve (BlockContext ec)
		{
			if (Expr == null) {
				if (ec.ReturnType == TypeManager.void_type)
					return true;

				if (ec.CurrentIterator != null) {
					Error_ReturnFromIterator (ec);
				} else {
					ec.Report.Error (126, loc,
						"An object of a type convertible to `{0}' is required for the return statement",
						ec.ReturnType.GetSignatureForError ());
				}

				return false;
			}

			Expr = Expr.Resolve (ec);

			AnonymousExpression am = ec.CurrentAnonymousMethod;
			if (am == null) {
				if (ec.ReturnType == TypeManager.void_type) {
					ec.Report.Error (127, loc,
						"`{0}': A return keyword must not be followed by any expression when method returns void",
						ec.GetSignatureForError ());
				}
			} else {
				if (am.IsIterator) {
					Error_ReturnFromIterator (ec);
					return false;
				}

				var l = am as AnonymousMethodBody;
				if (l != null && l.ReturnTypeInference != null && Expr != null) {
					l.ReturnTypeInference.AddCommonTypeBound (Expr.Type);
					return true;
				}
			}

			if (Expr == null)
				return false;

			if (Expr.Type != ec.ReturnType) {
				Expr = Convert.ImplicitConversionRequired (ec, Expr, ec.ReturnType, loc);

				if (Expr == null) {
					if (am != null) {
						ec.Report.Error (1662, loc,
							"Cannot convert `{0}' to delegate type `{1}' because some of the return types in the block are not implicitly convertible to the delegate return type",
							am.ContainerType, am.GetSignatureForError ());
					}
					return false;
				}
			}

			return true;			
		}