提交 da56be51 编写于 作者: Y yair halberstadt

Allow Deprecated Attribute on property accessors.

Forbid Obsolete/Deprecated on event accessors.

Give suitable error messages for Obsolete/Deprected on event accessors, and on property accessors pre-C# 8

Add further tests
上级 9c30cc3b
......@@ -762,6 +762,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to Attribute &apos;{0}&apos; is not valid on event accessors. It is only valid on &apos;{1}&apos; declarations..
/// </summary>
internal static string ERR_AttributeNotOnEventAccessor {
get {
return ResourceManager.GetString("ERR_AttributeNotOnEventAccessor", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Attribute &apos;{0}&apos; is not valid on this declaration type. It is only valid on &apos;{1}&apos; declarations..
/// </summary>
......@@ -11320,6 +11329,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to obsolete property accessors.
/// </summary>
internal static string IDS_FeatureObsoleteOnPropertyAccessor {
get {
return ResourceManager.GetString("IDS_FeatureObsoleteOnPropertyAccessor", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to optional parameter.
/// </summary>
......
......@@ -5796,4 +5796,10 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_FeatureInPreview" xml:space="preserve">
<value>The feature '{0}' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.</value>
</data>
</root>
<data name="ERR_AttributeNotOnEventAccessor" xml:space="preserve">
<value>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</value>
</data>
<data name="IDS_FeatureObsoleteOnPropertyAccessor" xml:space="preserve">
<value>obsolete property accessors</value>
</data>
</root>
\ No newline at end of file
......@@ -1598,7 +1598,7 @@ internal enum ErrorCode
ERR_PossibleAsyncIteratorWithoutYieldOrAwait = 8420,
ERR_StaticLocalFunctionCannotCaptureVariable = 8421,
ERR_StaticLocalFunctionCannotCaptureThis = 8422,
ERR_AttributeNotOnEventAccessor = 8423,
#region diagnostics introduced for recursive patterns
// 8501, // available
ERR_WrongNumberOfSubpatterns = 8502,
......
......@@ -175,6 +175,7 @@ internal enum MessageID
IDS_FeatureStaticLocalFunctions = MessageBase + 12755,
IDS_FeatureNameShadowingInNestedFunctions = MessageBase + 12756,
IDS_FeatureUnmanagedConstructedTypes = MessageBase + 12757,
IDS_FeatureObsoleteOnPropertyAccessor = MessageBase + 12758,
}
// Message IDs may refer to strings that need to be localized.
......@@ -279,6 +280,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case MessageID.IDS_FeatureStaticLocalFunctions:
case MessageID.IDS_FeatureNameShadowingInNestedFunctions:
case MessageID.IDS_FeatureUnmanagedConstructedTypes: // semantic check
case MessageID.IDS_FeatureObsoleteOnPropertyAccessor:
return LanguageVersion.CSharp8;
// C# 7.3 features.
......
......@@ -1164,6 +1164,9 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
{
arguments.GetOrCreateData<CommonMethodWellKnownAttributeData>().HasDynamicSecurityMethodAttribute = true;
}
else if (VerifyObsoleteAttributeAppliedToMethod(ref arguments, AttributeDescription.ObsoleteAttribute))
{
}
else if (VerifyObsoleteAttributeAppliedToMethod(ref arguments, AttributeDescription.DeprecatedAttribute))
{
}
......@@ -1213,9 +1216,14 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
{
if (this.IsAccessor())
{
// CS1667: Attribute '{0}' is not valid on property or event accessors. It is only valid on '{1}' declarations.
AttributeUsageInfo attributeUsage = arguments.Attribute.AttributeClass.GetAttributeUsageInfo();
arguments.Diagnostics.Add(ErrorCode.ERR_AttributeNotOnAccessor, arguments.AttributeSyntaxOpt.Name.Location, description.FullName, attributeUsage.GetValidTargetsErrorArgument());
if (this is SourceEventAccessorSymbol)
{
// CS1667: Attribute '{0}' is not valid on property or event accessors. It is only valid on '{1}' declarations.
AttributeUsageInfo attributeUsage = arguments.Attribute.AttributeClass.GetAttributeUsageInfo();
arguments.Diagnostics.Add(ErrorCode.ERR_AttributeNotOnEventAccessor, arguments.AttributeSyntaxOpt.Name.Location, description.FullName, attributeUsage.GetValidTargetsErrorArgument());
}
MessageID.IDS_FeatureObsoleteOnPropertyAccessor.CheckFeatureAvailability(arguments.Diagnostics, arguments.AttributeSyntaxOpt.Location);
}
return true;
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">Asynchronní příkaz foreach nejde použít pro proměnné typu {0}, protože {0} neobsahuje vhodnou veřejnou definici instance pro {1}.</target>
......@@ -712,6 +717,11 @@
<target state="translated">omezení obecného typu objektu</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">Eine asynchrone foreach-Anweisung kann nicht für Variablen vom Typ "{0}" verwendet werden, weil "{0}" keine geeignete öffentliche Instanzdefinition für "{1}" enthält.</target>
......@@ -712,6 +717,11 @@
<target state="translated">Einschränkung eines generischen Objekttyps</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">Una instrucción foreach asincrónica no puede funcionar en variables de tipo "{0}", porque "{0}" no contiene una definición de instancia pública adecuada para "{1}".</target>
......@@ -712,6 +717,11 @@
<target state="translated">restricción de tipo genérico de objeto</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">L'instruction foreach asynchrone ne peut pas fonctionner sur des variables de type '{0}', car '{0}' ne contient aucune définition d'instance publique appropriée pour '{1}'</target>
......@@ -712,6 +717,11 @@
<target state="translated">contrainte de type générique d'objet</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">L'istruzione foreach asincrona non può funzionare con variabili di tipo '{0}' perché '{0}' non contiene una definizione di istanza pubblica idonea per '{1}'</target>
......@@ -712,6 +717,11 @@
<target state="translated">vincolo di tipo generico object</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">'{0}' は '{1}' の適切なパブリック インスタンス定義を含んでいないため、型 '{0}' の変数に対して非同期 foreach ステートメントを使用することはできません</target>
......@@ -712,6 +717,11 @@
<target state="translated">オブジェクト ジェネリック型の制約</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">'{0}' 형식 변수에서 비동기 foreach 문을 수행할 수 없습니다. '{0}'에는 '{1}'의 적합한 공용 인스턴스 정의가 없기 때문입니다.</target>
......@@ -712,6 +717,11 @@
<target state="translated">개체 제네릭 형식 제약 조건</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">Asynchroniczna instrukcja foreach nie może operować na zmiennych typu „{0}”, ponieważ typ „{0}” nie zawiera odpowiedniej publicznej definicji wystąpienia elementu „{1}”</target>
......@@ -712,6 +717,11 @@
<target state="translated">ogólne ograniczenie typu obiektu</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">A instrução foreach assíncrona não pode operar em variáveis do tipo '{0}' porque '{0}' não contém uma definição da instância pública adequada para '{1}'</target>
......@@ -712,6 +717,11 @@
<target state="translated">restrição de tipo genérico de objeto</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">Асинхронный оператор foreach не работает с переменными типа "{0}", так как "{0}" не содержит подходящее открытое определение экземпляра для "{1}".</target>
......@@ -712,6 +717,11 @@
<target state="translated">ограничение универсального типа для объекта</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">'{0}', '{1}' için uygun bir genel örnek tanımı içermediğinden zaman uyumsuz foreach deyimi '{0}' türündeki değişkenlerle çalışmaz</target>
......@@ -712,6 +717,11 @@
<target state="translated">nesne genel tür kısıtlamaları</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">“{0}”不包含“{1}”的适当公共实例定义,因此异步 foreach 语句不能作用于“{0}”类型的变量</target>
......@@ -417,6 +422,11 @@
<target state="translated">对象泛型类型约束</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -32,6 +32,11 @@
<target state="new">It is not legal to use nullable reference type '{0}?' in an as expression; use the underlying type '{0}' instead.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AttributeNotOnEventAccessor">
<source>Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</source>
<target state="new">Attribute '{0}' is not valid on event accessors. It is only valid on '{1}' declarations.</target>
<note />
</trans-unit>
<trans-unit id="ERR_AwaitForEachMissingMember">
<source>Asynchronous foreach statement cannot operate on variables of type '{0}' because '{0}' does not contain a suitable public instance definition for '{1}'</source>
<target state="translated">因為 '{0}' 不包含適用於 '{1}' 的公用執行個體定義,所以非同步的 foreach 陳述式無法在類型為 '{0}' 的變數上運作</target>
......@@ -712,6 +717,11 @@
<target state="translated">物件泛型型別條件約束</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeatureObsoleteOnPropertyAccessor">
<source>obsolete property accessors</source>
<target state="new">obsolete property accessors</target>
<note />
</trans-unit>
<trans-unit id="IDS_FeaturePragmaWarningEnableOrSafeOnly">
<source>warning action enable or safeonly</source>
<target state="new">warning action enable or safeonly</target>
......
......@@ -5810,6 +5810,12 @@ public static class TestExtension
}
";
CreateCompilationWithMscorlib40(source, new[] { ExtensionAssemblyRef }).VerifyDiagnostics(
// (98,10): error CS8423: Attribute 'System.ObsoleteAttribute' is not valid on event accessors. It is only valid on 'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.
// [Obsolete] add {}
Diagnostic(ErrorCode.ERR_AttributeNotOnEventAccessor, "Obsolete").WithArguments("System.ObsoleteAttribute", "class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate").WithLocation(98, 10),
// (99,10): error CS8423: Attribute 'System.ObsoleteAttribute' is not valid on event accessors. It is only valid on 'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.
// [Obsolete("Don't use remove accessor")] remove {}
Diagnostic(ErrorCode.ERR_AttributeNotOnEventAccessor, "Obsolete").WithArguments("System.ObsoleteAttribute", "class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate").WithLocation(99, 10),
// (8,9): warning CS0612: 'Test.ObsoleteMethod1()' is obsolete
// ObsoleteMethod1();
Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "ObsoleteMethod1()").WithArguments("Test.ObsoleteMethod1()").WithLocation(8, 9),
......@@ -6883,9 +6889,6 @@ class D
}";
var comp = CreateCompilation(new[] { Parse(source0), Parse(source1) });
comp.VerifyDiagnostics(
// (9,17): error CS1667: Attribute 'Windows.Foundation.Metadata.DeprecatedAttribute' is not valid on property or event accessors. It is only valid on 'assembly, module, class, struct, enum, constructor, method, property, indexer, field, event, interface, parameter, delegate, return, type parameter' declarations.
// object R { [Deprecated(null, DeprecationType.Deprecate, 0)] get { return new C(); } }
Diagnostic(ErrorCode.ERR_AttributeNotOnAccessor, "Deprecated").WithArguments("Windows.Foundation.Metadata.DeprecatedAttribute", "assembly, module, class, struct, enum, constructor, method, property, indexer, field, event, interface, parameter, delegate, return, type parameter").WithLocation(9, 17),
// (7,33): warning CS0612: 'A' is obsolete
// object P { get { return new A(); } }
Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "A").WithArguments("A").WithLocation(7, 33));
......@@ -6937,12 +6940,12 @@ class D
}";
var comp = CreateCompilation(new[] { Parse(source0), Parse(source1) });
comp.VerifyDiagnostics(
// (21,10): error CS1667: Attribute 'Windows.Foundation.Metadata.DeprecatedAttribute' is not valid on property or event accessors. It is only valid on 'assembly, module, class, struct, enum, constructor, method, property, indexer, field, event, interface, parameter, delegate, return, type parameter' declarations.
// [Deprecated(null, DeprecationType.Deprecate, 0)] remove { M(new C()); }
Diagnostic(ErrorCode.ERR_AttributeNotOnAccessor, "Deprecated").WithArguments("Windows.Foundation.Metadata.DeprecatedAttribute", "assembly, module, class, struct, enum, constructor, method, property, indexer, field, event, interface, parameter, delegate, return, type parameter").WithLocation(21, 10),
// (11,24): warning CS0612: 'A' is obsolete
// remove { M(new A()); }
Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "A").WithArguments("A").WithLocation(11, 24));
Diagnostic(ErrorCode.WRN_DeprecatedSymbol, "A").WithArguments("A").WithLocation(11, 24),
// (21,10): error CS8423: Attribute 'Windows.Foundation.Metadata.DeprecatedAttribute' is not valid on event accessors. It is only valid on 'assembly, module, class, struct, enum, constructor, method, property, indexer, field, event, interface, parameter, delegate, return, type parameter' declarations.
// [Deprecated(null, DeprecationType.Deprecate, 0)] remove { M(new C()); }
Diagnostic(ErrorCode.ERR_AttributeNotOnEventAccessor, "Deprecated").WithArguments("Windows.Foundation.Metadata.DeprecatedAttribute", "assembly, module, class, struct, enum, constructor, method, property, indexer, field, event, interface, parameter, delegate, return, type parameter").WithLocation(21, 10));
}
[Fact]
......@@ -8079,27 +8082,33 @@ void Test()
Class2 x2 = null;
Class3 x3 = null;
Class4 x4 = null;
Class6 x6 = new Class6();
object x5;
x5=x1;
x5 = x2;
x5 = x3;
x5 = x4;
x5 = x6.P1;
x6.P1 = 1;
x6.E1 += null;
x6.E1 -= null;
}
}
class Class6
{
int P1
public int P1
{
[Deprecated(""P1.get is deprecated."", DeprecationType.Remove, 1)]
get
{
return 1;
}
set {}
}
event System.Action E1
public event System.Action E1
{
[Deprecated(""E1.add is deprecated."", DeprecationType.Remove, 1)]
add
......@@ -8114,12 +8123,6 @@ int P1
var compilation2 = CreateEmptyCompilation(source2, WinRtRefs.Concat(new[] { new CSharpCompilationReference(compilation1) }), TestOptions.ReleaseDll);
var expected = new[] {
// (25,10): error CS1667: Attribute 'Windows.Foundation.Metadata.DeprecatedAttribute' is not valid on property or event accessors. It is only valid on 'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.
// [Deprecated("P1.get is deprecated.", DeprecationType.Remove, 1)]
Diagnostic(ErrorCode.ERR_AttributeNotOnAccessor, "Deprecated").WithArguments("Windows.Foundation.Metadata.DeprecatedAttribute", "class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate").WithLocation(25, 10),
// (34,10): error CS1667: Attribute 'Windows.Foundation.Metadata.DeprecatedAttribute' is not valid on property or event accessors. It is only valid on 'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.
// [Deprecated("E1.add is deprecated.", DeprecationType.Remove, 1)]
Diagnostic(ErrorCode.ERR_AttributeNotOnAccessor, "Deprecated").WithArguments("Windows.Foundation.Metadata.DeprecatedAttribute", "class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate").WithLocation(34, 10),
// (8,9): warning CS0618: 'Class1' is obsolete: 'Class1 is deprecated.'
// Class1 x1 = null;
Diagnostic(ErrorCode.WRN_DeprecatedSymbolStr, "Class1").WithArguments("Class1", "Class1 is deprecated.").WithLocation(8, 9),
......@@ -8131,7 +8134,13 @@ int P1
Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "Class3").WithArguments("Class3", "Class3 is deprecated.").WithLocation(10, 9),
// (11,9): error CS0619: 'Class4' is obsolete: 'Class4 is deprecated.'
// Class4 x4 = null;
Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "Class4").WithArguments("Class4", "Class4 is deprecated.").WithLocation(11, 9)
Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "Class4").WithArguments("Class4", "Class4 is deprecated.").WithLocation(11, 9),
// (19,14): error CS0619: 'Class6.P1.get' is obsolete: 'P1.get is deprecated.'
// x5 = x6.P1;
Diagnostic(ErrorCode.ERR_DeprecatedSymbolStr, "x6.P1").WithArguments("Class6.P1.get", "P1.get is deprecated.").WithLocation(19, 14),
// (40,10): error CS8423: Attribute 'Windows.Foundation.Metadata.DeprecatedAttribute' is not valid on event accessors. It is only valid on 'class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate' declarations.
// [Deprecated("E1.add is deprecated.", DeprecationType.Remove, 1)]
Diagnostic(ErrorCode.ERR_AttributeNotOnEventAccessor, "Deprecated").WithArguments("Windows.Foundation.Metadata.DeprecatedAttribute", "class, struct, enum, constructor, method, property, indexer, field, event, interface, delegate").WithLocation(40, 10)
};
compilation2.VerifyDiagnostics(expected);
......@@ -9110,5 +9119,38 @@ class C
CreateCompilation(code).VerifyDiagnostics().VerifyEmitDiagnostics();
}
[Fact]
public void TestObsoleteOnPropertyAccessorCSharp7()
{
var code = @"
class C
{
public int Prop { [Obsolete] get; set; }
}
";
CreateCompilation(code, parseOptions: new CSharpParseOptions(LanguageVersion.CSharp7_3)).VerifyDiagnostics(
// (4,24): error CS8652: The feature 'obsolete property accessors' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// public int Prop { [Obsolete] get; set; }
Diagnostic(ErrorCode.ERR_FeatureInPreview, "Obsolete").WithArguments("obsolete property accessors").WithLocation(4, 24));
}
[Fact]
public void TestDeprecatedOnPropertyAccessorCSharp7()
{
var code = @"
using Windows.Foundation.Metadata;
class C
{
public int Prop { [Deprecated(""don't use this"", DeprecationType.Remove, 50331648u)] get; set; }
}
";
CreateEmptyCompilation(code, references: WinRtRefs, parseOptions: new CSharpParseOptions(LanguageVersion.CSharp7_3)).VerifyDiagnostics(
// (5,24): error CS8652: The feature 'obsolete property accessors' is currently in Preview and *unsupported*. To use Preview features, use the 'preview' language version.
// public int Prop { [Deprecated("don't use this", DeprecationType.Remove, 50331648u)] get; set; }
Diagnostic(ErrorCode.ERR_FeatureInPreview, @"Deprecated(""don't use this"", DeprecationType.Remove, 50331648u)").WithArguments("obsolete property accessors").WithLocation(5, 24));
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册