Mono.CSharp.BlockVariableDeclaration.Resolve C# (CSharp) Method

Resolve() public method

public Resolve ( BlockContext bc ) : bool
bc BlockContext
return bool
		public override bool Resolve (BlockContext bc)
		{
			if (li.Type == null) {
				TypeSpec type = null;
				if (type_expr is VarExpr) {
					//
					// C# 3.0 introduced contextual keywords (var) which behaves like a type if type with
					// same name exists or as a keyword when no type was found
					// 
					var texpr = type_expr.ResolveAsTypeTerminal (bc, true);
					if (texpr == null) {
						if (RootContext.Version < LanguageVersion.V_3)
							bc.Report.FeatureIsNotAvailable (loc, "implicitly typed local variable");

						if (li.IsFixed) {
							bc.Report.Error (821, loc, "A fixed statement cannot use an implicitly typed local variable");
							return false;
						}

						if (li.IsConstant) {
							bc.Report.Error (822, loc, "An implicitly typed local variable cannot be a constant");
							return false;
						}

						if (Initializer == null) {
							bc.Report.Error (818, loc, "An implicitly typed local variable declarator must include an initializer");
							return false;
						}

						if (declarators != null) {
							bc.Report.Error (819, loc, "An implicitly typed local variable declaration cannot include multiple declarators");
							declarators = null;
						}

						Initializer = Initializer.Resolve (bc);
						if (Initializer != null) {
							((VarExpr) type_expr).InferType (bc, Initializer);
							type = type_expr.Type;
						}
					}
				}

				if (type == null) {
					var texpr = type_expr.ResolveAsTypeTerminal (bc, false);
					if (texpr == null)
						return false;

					type = texpr.Type;

					if (li.IsConstant && !type.IsConstantCompatible) {
						Const.Error_InvalidConstantType (type, loc, bc.Report);
					}
				}

				if (type.IsStatic)
					FieldBase.Error_VariableOfStaticClass (loc, li.Name, type, bc.Report);

				if (type.IsPointer && !bc.IsUnsafe)
					Expression.UnsafeError (bc, loc);

				li.Type = type;
			}

			bool eval_global = RootContext.StatementMode && bc.CurrentBlock is ToplevelBlock;
			if (eval_global) {
				CreateEvaluatorVariable (bc, li);
			} else {
				li.PrepareForFlowAnalysis (bc);
			}

			if (initializer != null) {
				initializer = ResolveInitializer (bc, li, initializer);
				// li.Variable.DefinitelyAssigned 
			}

			if (declarators != null) {
				foreach (var d in declarators) {
					d.Variable.Type = li.Type;
					if (eval_global) {
						CreateEvaluatorVariable (bc, d.Variable);
					} else {
						d.Variable.PrepareForFlowAnalysis (bc);
					}

					if (d.Initializer != null) {
						d.Initializer = ResolveInitializer (bc, d.Variable, d.Initializer);
						// d.Variable.DefinitelyAssigned 
					}
				}
			}

			return true;
		}