Example #1
0
        // <summary>
        //   A struct's constructor must always assign all fields.
        //   This method checks whether it actually does so.
        // </summary>
        public bool IsFullyInitialized(FlowAnalysisContext fc, VariableInfo vi, Location loc)
        {
            if (struct_info == null)
            {
                return(true);
            }

            bool ok = true;

            for (int i = 0; i < struct_info.Count; i++)
            {
                var field = struct_info.Fields[i];

                if (!fc.IsStructFieldDefinitelyAssigned(vi, field.Name))
                {
                    var bf = field.MemberDefinition as Property.BackingFieldDeclaration;
                    if (bf != null)
                    {
                        if (bf.Initializer != null)
                        {
                            continue;
                        }

                        fc.Report.Error(843, loc,
                                        "An automatically implemented property `{0}' must be fully assigned before control leaves the constructor. Consider calling the default struct contructor from a constructor initializer",
                                        field.GetSignatureForError());

                        ok = false;
                        continue;
                    }

                    fc.Report.Error(171, loc,
                                    "Field `{0}' must be fully assigned before control leaves the constructor",
                                    field.GetSignatureForError());
                    ok = false;
                }
            }

            return(ok);
        }
Example #2
0
		// <summary>
		//   A struct's constructor must always assign all fields.
		//   This method checks whether it actually does so.
		// </summary>
		public bool IsFullyInitialized (FlowAnalysisContext fc, VariableInfo vi, Location loc)
		{
			if (struct_info == null)
				return true;

			bool ok = true;
			for (int i = 0; i < struct_info.Count; i++) {
				var field = struct_info.Fields[i];

				if (!fc.IsStructFieldDefinitelyAssigned (vi, field.Name)) {
					var bf = field.MemberDefinition as Property.BackingFieldDeclaration;
					if (bf != null) {
						if (bf.Initializer != null)
							continue;

						fc.Report.Error (843, loc,
							"An automatically implemented property `{0}' must be fully assigned before control leaves the constructor. Consider calling the default struct contructor from a constructor initializer",
							field.GetSignatureForError ());

						ok = false;
						continue;
					}

					fc.Report.Error (171, loc,
						"Field `{0}' must be fully assigned before control leaves the constructor",
						field.GetSignatureForError ());
					ok = false;
				}
			}

			return ok;
		}