提交 c2c0fcf6 编写于 作者: O Omar Tawfik

Added missing warnings to tests

上级 116b720a
......@@ -1631,26 +1631,28 @@ public static void Main()
comp.VerifyDiagnostics(
// (12,21): warning CS0108: 'Base.Derived.Method()' hides inherited member 'Base.Method()'. Use the new keyword if hiding was intended.
// static void Method() { Console.WriteLine("Derived.Method()"); }
Diagnostic(ErrorCode.WRN_NewRequired, "Method").WithArguments("Base.Derived.Method()", "Base.Method()"),
Diagnostic(ErrorCode.WRN_NewRequired, "Method").WithArguments("Base.Derived.Method()", "Base.Method()").WithLocation(12, 21),
// (62,13): warning CS0108: 'Base2.Derived2.Field' hides inherited member 'Base2.Field'. Use the new keyword if hiding was intended.
// int Field = 2;
Diagnostic(ErrorCode.WRN_NewRequired, "Field").WithArguments("Base2.Derived2.Field", "Base2.Field"),
Diagnostic(ErrorCode.WRN_NewRequired, "Field").WithArguments("Base2.Derived2.Field", "Base2.Field").WithLocation(62, 13),
// (63,20): warning CS0108: 'Base2.Derived2.Field2' hides inherited member 'Base2.Field2'. Use the new keyword if hiding was intended.
// public int Field2 = 3;
Diagnostic(ErrorCode.WRN_NewRequired, "Field2").WithArguments("Base2.Derived2.Field2", "Base2.Field2"),
Diagnostic(ErrorCode.WRN_NewRequired, "Field2").WithArguments("Base2.Derived2.Field2", "Base2.Field2").WithLocation(63, 20),
// (74,22): warning CS0108: 'Base2.Derived2.Type2<T>' hides inherited member 'Base2.Type2<T>'. Use the new keyword if hiding was intended.
// public class Type2<T>
Diagnostic(ErrorCode.WRN_NewRequired, "Type2").WithArguments("Base2.Derived2.Type2<T>", "Base2.Type2<T>"),
Diagnostic(ErrorCode.WRN_NewRequired, "Type2").WithArguments("Base2.Derived2.Type2<T>", "Base2.Type2<T>").WithLocation(74, 22),
// (99,13): warning CS0109: The member 'Derived3.Field' does not hide an inherited member. The new keyword is not required.
// new int Field = 2;
Diagnostic(ErrorCode.WRN_NewNotRequired, "Field").WithArguments("Derived3.Field"),
Diagnostic(ErrorCode.WRN_NewNotRequired, "Field").WithArguments("Derived3.Field").WithLocation(99, 13),
// (101,26): warning CS0108: 'Derived3.Field2' hides inherited member 'Base3.Field2'. Use the new keyword if hiding was intended.
// protected static int Field2 = 1;
Diagnostic(ErrorCode.WRN_NewRequired, "Field2").WithArguments("Derived3.Field2", "Base3.Field2"),
Diagnostic(ErrorCode.WRN_NewRequired, "Field2").WithArguments("Derived3.Field2", "Base3.Field2").WithLocation(101, 26),
// (92,9): warning CS0414: The field 'Base3.Field' is assigned but its value is never used
// int Field = 1;
Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "Field").WithArguments("Base3.Field")
);
Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "Field").WithArguments("Base3.Field").WithLocation(92, 9),
// (99,13): warning CS0414: The field 'Derived3.Field' is assigned but its value is never used
// new int Field = 2;
Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "Field").WithArguments("Derived3.Field").WithLocation(99, 13));
}
[Fact]
......
......@@ -2543,12 +2543,18 @@ class D : C
Assert.Equal(0, ohmD.HiddenMembers.Length);
comp.VerifyDiagnostics(
// (19,41): error CS1715: 'D.E': type must be 'System.Func<int>' to match overridden member 'C.E'
// (19,41): error CS1715: 'D.E': type must be 'Func<int>' to match overridden member 'C.E'
// public override event System.Action E;
Diagnostic(ErrorCode.ERR_CantChangeTypeOnOverride, "E").WithArguments("D.E", "C.E", "System.Func<int>"),
Diagnostic(ErrorCode.ERR_CantChangeTypeOnOverride, "E").WithArguments("D.E", "C.E", "System.Func<int>").WithLocation(19, 41),
// (19,41): warning CS0067: The event 'D.E' is never used
// public override event System.Action E;
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("D.E"));
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("D.E").WithLocation(19, 41),
// (9,41): warning CS0067: The event 'B.E' is never used
// public override event System.Action E;
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("B.E").WithLocation(9, 41),
// (14,47): warning CS0067: The event 'C.E' is never used
// public new virtual event System.Func<int> E;
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "E").WithArguments("C.E").WithLocation(14, 47));
}
[WorkItem(545653, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/545653")]
......
......@@ -921,7 +921,10 @@ public static void f()
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (6,22): error CS0068: 'I.d': event in interface cannot have initializer
// event MyDelegate d = new MyDelegate(M.f); // CS0068
Diagnostic(ErrorCode.ERR_InterfaceEventInitializer, "d").WithArguments("I.d"));
Diagnostic(ErrorCode.ERR_InterfaceEventInitializer, "d").WithArguments("I.d").WithLocation(6, 22),
// (6,22): warning CS0067: The event 'I.d' is never used
// event MyDelegate d = new MyDelegate(M.f); // CS0068
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "d").WithArguments("I.d").WithLocation(6, 22));
}
[Fact]
......@@ -979,7 +982,10 @@ abstract class Test
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (6,29): error CS0074: 'Test.e': abstract event cannot have initializer
// public abstract event D e = null; // CS0074
Diagnostic(ErrorCode.ERR_AbstractEventInitializer, "e").WithArguments("Test.e"));
Diagnostic(ErrorCode.ERR_AbstractEventInitializer, "e").WithArguments("Test.e").WithLocation(6, 29),
// (6,29): warning CS0414: The field 'Test.e' is assigned but its value is never used
// public abstract event D e = null; // CS0074
Diagnostic(ErrorCode.WRN_UnreferencedFieldAssg, "e").WithArguments("Test.e").WithLocation(6, 29));
}
[Fact]
......@@ -1991,7 +1997,9 @@ abstract class B : A
var comp = DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text,
new ErrorDescription { Code = (int)ErrorCode.ERR_StaticNotVirtual, Line = 7, Column = 51 },
new ErrorDescription { Code = (int)ErrorCode.ERR_StaticNotVirtual, Line = 8, Column = 47 },
new ErrorDescription { Code = (int)ErrorCode.ERR_StaticNotVirtual, Line = 9, Column = 50 });
new ErrorDescription { Code = (int)ErrorCode.ERR_StaticNotVirtual, Line = 9, Column = 50 },
new ErrorDescription { Code = (int)ErrorCode.WRN_UnreferencedEvent, Line = 7, Column = 51, IsWarning = true },
new ErrorDescription { Code = (int)ErrorCode.WRN_UnreferencedEvent, Line = 8, Column = 47, IsWarning = true });
}
[Fact]
......@@ -2069,16 +2077,19 @@ class B : A
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (9,51): error CS0113: A member 'B.Q' marked as override cannot be marked as new or virtual
// internal virtual override event System.Action Q;
Diagnostic(ErrorCode.ERR_OverrideNotNew, "Q").WithArguments("B.Q"),
Diagnostic(ErrorCode.ERR_OverrideNotNew, "Q").WithArguments("B.Q").WithLocation(9, 51),
// (8,48): error CS0113: A member 'B.P' marked as override cannot be marked as new or virtual
// protected new override event System.Action P;
Diagnostic(ErrorCode.ERR_OverrideNotNew, "P").WithArguments("B.P"),
Diagnostic(ErrorCode.ERR_OverrideNotNew, "P").WithArguments("B.P").WithLocation(8, 48),
// (8,48): warning CS0067: The event 'B.P' is never used
// protected new override event System.Action P;
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "P").WithArguments("B.P"),
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "P").WithArguments("B.P").WithLocation(8, 48),
// (9,51): warning CS0067: The event 'B.Q' is never used
// internal virtual override event System.Action Q;
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "Q").WithArguments("B.Q"));
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "Q").WithArguments("B.Q").WithLocation(9, 51),
// (4,42): warning CS0067: The event 'A.Q' is never used
// internal virtual event System.Action Q;
Diagnostic(ErrorCode.WRN_UnreferencedEvent, "Q").WithArguments("A.Q").WithLocation(4, 42));
}
[Fact]
......@@ -8935,16 +8946,18 @@ abstract class A3 : B3
}
";
CreateCompilationWithMscorlib(text).VerifyDiagnostics(
// (31,32): error CS0533: 'NS.A3.foo' hides inherited abstract member 'NS.B3.foo()'
// (31,32): error CS0533: 'A3.foo' hides inherited abstract member 'B3.foo()'
// new protected double[] foo; // CS0533
Diagnostic(ErrorCode.ERR_HidingAbstractMethod, "foo").WithArguments("NS.A3.foo", "NS.B3.foo()"),
Diagnostic(ErrorCode.ERR_HidingAbstractMethod, "foo").WithArguments("NS.A3.foo", "NS.B3.foo()").WithLocation(31, 32),
// (9,24): error CS0533: 'A1.foo' hides inherited abstract member 'B1.foo'
// new protected enum foo { } // CS0533
Diagnostic(ErrorCode.ERR_HidingAbstractMethod, "foo").WithArguments("A1.foo", "B1.foo"),
Diagnostic(ErrorCode.ERR_HidingAbstractMethod, "foo").WithArguments("A1.foo", "B1.foo").WithLocation(9, 24),
// (18,36): error CS0533: 'A1.A2.foo' hides inherited abstract member 'A1.B2.foo()'
// new public delegate object foo(); // CS0533
Diagnostic(ErrorCode.ERR_HidingAbstractMethod, "foo").WithArguments("A1.A2.foo", "A1.B2.foo()")
);
Diagnostic(ErrorCode.ERR_HidingAbstractMethod, "foo").WithArguments("A1.A2.foo", "A1.B2.foo()").WithLocation(18, 36),
// (31,32): warning CS0649: Field 'A3.foo' is never assigned to, and will always have its default value null
// new protected double[] foo; // CS0533
Diagnostic(ErrorCode.WRN_UnassignedInternalField, "foo").WithArguments("NS.A3.foo", "null").WithLocation(31, 32));
}
[WorkItem(540464, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540464")]
......
......@@ -182,7 +182,7 @@ public static void VerifyErrorCodes(IEnumerable<Diagnostic> actualErrors, params
Assert.True(experr.Column == acterr.Column, String.Format("Col {0}!={1}", experr.Column, acterr.Column));
}
Assert.Equal(experr.IsWarning, acterr.IsWarning);
Assert.True(experr.IsWarning == acterr.IsWarning, String.Format("IsWarning {0}!={1}", experr.IsWarning, acterr.IsWarning));
//if the expected contains parameters, validate those too.
if (experr.Parameters != null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册