public override void VerifyMembers ()
{
//
// Check for internal or private fields that were never assigned
//
if (!IsCompilerGenerated && Compiler.Settings.WarningLevel >= 3 && this == PartialContainer) {
bool is_type_exposed = Kind == MemberKind.Struct || IsExposedFromAssembly ();
foreach (var member in members) {
if (member is Event) {
//
// An event can be assigned from same class only, report
// this warning for all accessibility modes
//
if (!member.IsUsed && !PartialContainer.HasStructLayout)
Report.Warning (67, 3, member.Location, "The event `{0}' is never used", member.GetSignatureForError ());
continue;
}
if ((member.ModFlags & Modifiers.AccessibilityMask) != Modifiers.PRIVATE) {
if (is_type_exposed)
continue;
member.SetIsUsed ();
}
var f = member as Field;
if (f == null)
continue;
if (!member.IsUsed) {
if (!PartialContainer.HasStructLayout) {
if ((member.caching_flags & Flags.IsAssigned) == 0) {
Report.Warning (169, 3, member.Location, "The private field `{0}' is never used", member.GetSignatureForError ());
} else {
Report.Warning (414, 3, member.Location, "The private field `{0}' is assigned but its value is never used",
member.GetSignatureForError ());
}
}
continue;
}
if ((f.caching_flags & Flags.IsAssigned) != 0)
continue;
//
// Only report 649 on level 4
//
if (Compiler.Settings.WarningLevel < 4)
continue;
//
// Don't be pedantic when type requires specific layout
//
if (f.OptAttributes != null || PartialContainer.HasStructLayout)
continue;
Constant c = New.Constantify (f.MemberType, f.Location);
string value;
if (c != null) {
value = c.GetValueAsLiteral ();
} else if (TypeSpec.IsReferenceType (f.MemberType)) {
value = "null";
} else {
value = null;
}
if (value != null)
value = " `" + value + "'";
Report.Warning (649, 4, f.Location, "Field `{0}' is never assigned to, and will always have its default value{1}",
f.GetSignatureForError (), value);
}
}
base.VerifyMembers ();
}