From 9d1754a337456e211f5947aee398a86f34bdbce9 Mon Sep 17 00:00:00 2001 From: Fred Silberberg Date: Wed, 18 May 2022 13:31:59 -0700 Subject: [PATCH] Add support for CompilerFeatureRequiredAttribute (#61113) Adds support for decoding and reporting errors when `CompilerFeatureRequiredAttribute` is encountered on metadata type symbols. We also block applying the attribute by hand in both C# and VB. --- .../CSharp/Portable/CSharpResources.resx | 3 + .../CSharp/Portable/Errors/ErrorCode.cs | 1 + .../CSharp/Portable/Symbols/EventSymbol.cs | 10 +- .../CSharp/Portable/Symbols/FieldSymbol.cs | 12 +- .../Symbols/Metadata/PE/PEAssemblySymbol.cs | 22 + .../Symbols/Metadata/PE/PEEventSymbol.cs | 20 + .../Symbols/Metadata/PE/PEFieldSymbol.cs | 20 + .../Symbols/Metadata/PE/PEMethodSymbol.cs | 39 + .../Symbols/Metadata/PE/PEModuleSymbol.cs | 21 + .../Symbols/Metadata/PE/PENamedTypeSymbol.cs | 54 +- .../Symbols/Metadata/PE/PEParameterSymbol.cs | 20 + .../Symbols/Metadata/PE/PEPropertySymbol.cs | 32 + .../Metadata/PE/PETypeParameterSymbol.cs | 19 +- .../Symbols/Metadata/PE/PEUtilities.cs | 19 + .../CSharp/Portable/Symbols/MethodSymbol.cs | 12 +- .../Portable/Symbols/ParameterSymbol.cs | 12 +- .../CSharp/Portable/Symbols/PropertySymbol.cs | 12 +- .../FieldSymbolWithAttributesAndModifiers.cs | 2 +- .../Symbols/Source/SourceAssemblySymbol.cs | 2 +- .../Source/SourceComplexParameterSymbol.cs | 2 +- .../Symbols/Source/SourceEventSymbol.cs | 2 +- .../Symbols/Source/SourceFieldSymbol.cs | 4 +- .../SourceMethodSymbolWithAttributes.cs | 2 +- .../Symbols/Source/SourceModuleSymbol.cs | 2 +- .../Symbols/Source/SourceNamedTypeSymbol.cs | 2 +- .../Source/SourcePropertySymbolBase.cs | 2 +- .../Source/SourceTypeParameterSymbol.cs | 10 +- .../CSharp/Portable/Symbols/Symbol.cs | 13 +- .../Portable/Symbols/Symbol_Attributes.cs | 20 +- .../SynthesizedBackingFieldSymbol.cs | 4 +- .../CSharp/Portable/Symbols/TypeSymbol.cs | 15 +- .../Portable/xlf/CSharpResources.cs.xlf | 5 + .../Portable/xlf/CSharpResources.de.xlf | 5 + .../Portable/xlf/CSharpResources.es.xlf | 5 + .../Portable/xlf/CSharpResources.fr.xlf | 5 + .../Portable/xlf/CSharpResources.it.xlf | 5 + .../Portable/xlf/CSharpResources.ja.xlf | 5 + .../Portable/xlf/CSharpResources.ko.xlf | 5 + .../Portable/xlf/CSharpResources.pl.xlf | 5 + .../Portable/xlf/CSharpResources.pt-BR.xlf | 5 + .../Portable/xlf/CSharpResources.ru.xlf | 5 + .../Portable/xlf/CSharpResources.tr.xlf | 5 + .../Portable/xlf/CSharpResources.zh-Hans.xlf | 5 + .../Portable/xlf/CSharpResources.zh-Hant.xlf | 5 + .../CSharpCompilerFeatureRequiredTests.cs | 692 ++++++++++++++++ .../Core/Portable/MetadataReader/PEModule.cs | 60 +- .../Attributes/AttributeDescription.cs | 1 + .../CompilerFeatureRequiredFeatures.cs | 15 + .../Core/BaseCompilerFeatureRequiredTests.cs | 710 +++++++++++++++++ .../Test/Utilities/CSharp/CSharpTestBase.cs | 16 + .../VisualBasic/Portable/Binding/Binder.vb | 2 +- .../Portable/Errors/ErrorFactories.vb | 1 + .../VisualBasic/Portable/Errors/Errors.vb | 5 +- .../Portable/Symbols/ArrayTypeSymbol.vb | 5 +- .../Portable/Symbols/EventSymbol.vb | 13 +- .../Portable/Symbols/FieldSymbol.vb | 20 +- .../Symbols/Metadata/PE/PEAssemblySymbol.vb | 25 + .../Symbols/Metadata/PE/PEEventSymbol.vb | 26 +- .../Symbols/Metadata/PE/PEFieldSymbol.vb | 13 + .../Symbols/Metadata/PE/PEMethodSymbol.vb | 42 +- .../Symbols/Metadata/PE/PEModuleSymbol.vb | 27 +- .../Symbols/Metadata/PE/PENamedTypeSymbol.vb | 42 +- .../Symbols/Metadata/PE/PEParameterSymbol.vb | 18 + .../Symbols/Metadata/PE/PEPropertySymbol.vb | 33 +- .../Metadata/PE/PETypeParameterSymbol.vb | 19 +- .../Symbols/Metadata/PE/PEUtilities.vb | 18 + .../Portable/Symbols/MethodSymbol.vb | 31 +- .../Portable/Symbols/NamedTypeSymbol.vb | 9 +- .../Portable/Symbols/ParameterSymbol.vb | 14 +- .../Portable/Symbols/PropertySymbol.vb | 31 +- .../VisualBasic/Portable/Symbols/Symbol.vb | 35 +- .../Portable/Symbols/Symbol_Attributes.vb | 2 + .../Portable/Symbols/TypeSymbol.vb | 12 +- .../VisualBasic/Portable/VBResources.resx | 8 +- .../Portable/xlf/VBResources.cs.xlf | 10 + .../Portable/xlf/VBResources.de.xlf | 10 + .../Portable/xlf/VBResources.es.xlf | 10 + .../Portable/xlf/VBResources.fr.xlf | 10 + .../Portable/xlf/VBResources.it.xlf | 10 + .../Portable/xlf/VBResources.ja.xlf | 10 + .../Portable/xlf/VBResources.ko.xlf | 10 + .../Portable/xlf/VBResources.pl.xlf | 10 + .../Portable/xlf/VBResources.pt-BR.xlf | 10 + .../Portable/xlf/VBResources.ru.xlf | 10 + .../Portable/xlf/VBResources.tr.xlf | 10 + .../Portable/xlf/VBResources.zh-Hans.xlf | 10 + .../Portable/xlf/VBResources.zh-Hant.xlf | 10 + ...VisualBasicCompilerFeatureRequiredTests.vb | 739 ++++++++++++++++++ 88 files changed, 3086 insertions(+), 203 deletions(-) create mode 100644 src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEUtilities.cs create mode 100644 src/Compilers/CSharp/Test/Symbol/Symbols/CSharpCompilerFeatureRequiredTests.cs create mode 100644 src/Compilers/Core/Portable/Symbols/CompilerFeatureRequiredFeatures.cs create mode 100644 src/Compilers/Test/Core/BaseCompilerFeatureRequiredTests.cs create mode 100644 src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEUtilities.vb create mode 100644 src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/VisualBasicCompilerFeatureRequiredTests.vb diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 2db2cf928bb1b..7bb345340c74c 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -7133,4 +7133,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ relaxed shift operator + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + diff --git a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs index a14a1a8c37f62..baaabffbeec5e 100644 --- a/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs +++ b/src/Compilers/CSharp/Portable/Errors/ErrorCode.cs @@ -2087,5 +2087,6 @@ internal enum ErrorCode ERR_RequiredMembersBaseTypeInvalid = 9509, ERR_ChainingToSetsRequiredMembersRequiresSetsRequiredMembers = 9510, ERR_NewConstraintCannotHaveRequiredMembers = 9511, + ERR_UnsupportedCompilerFeature = 9512, } } diff --git a/src/Compilers/CSharp/Portable/Symbols/EventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/EventSymbol.cs index ef4e73e663137..42664a4724719 100644 --- a/src/Compilers/CSharp/Portable/Symbols/EventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/EventSymbol.cs @@ -307,20 +307,14 @@ internal bool CalculateUseSiteDiagnostic(ref UseSiteInfo result) return false; } - protected override int HighestPriorityUseSiteError - { - get - { - return (int)ErrorCode.ERR_BindToBogus; - } - } + protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code) => code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BindToBogus; public sealed override bool HasUnsupportedMetadata { get { DiagnosticInfo? info = GetUseSiteInfo().DiagnosticInfo; - return (object?)info != null && info.Code == (int)ErrorCode.ERR_BindToBogus; + return (object?)info != null && info.Code is (int)ErrorCode.ERR_BindToBogus or (int)ErrorCode.ERR_UnsupportedCompilerFeature; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs index 02c70ada96c12..043cc415d096b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/FieldSymbol.cs @@ -373,22 +373,16 @@ internal bool CalculateUseSiteDiagnostic(ref UseSiteInfo result) } /// - /// Return error code that has highest priority while calculating use site error for this symbol. + /// Returns true if the error code is highest priority while calculating use site error for this symbol. /// - protected override int HighestPriorityUseSiteError - { - get - { - return (int)ErrorCode.ERR_BindToBogus; - } - } + protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code) => code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BindToBogus; public sealed override bool HasUnsupportedMetadata { get { DiagnosticInfo info = GetUseSiteInfo().DiagnosticInfo; - return (object)info != null && info.Code == (int)ErrorCode.ERR_BindToBogus; + return (object)info != null && info.Code is (int)ErrorCode.ERR_BindToBogus or (int)ErrorCode.ERR_UnsupportedCompilerFeature; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEAssemblySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEAssemblySymbol.cs index 8415f05846631..6beb3835b6b24 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEAssemblySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEAssemblySymbol.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Reflection.Metadata.Ecma335; +using System.Threading; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE @@ -63,6 +64,10 @@ internal sealed class PEAssemblySymbol : MetadataOrSourceAssemblySymbol /// private ImmutableArray _lazyCustomAttributes; +#nullable enable + private DiagnosticInfo? _lazyCachedCompilerFeatureRequiredDiagnosticInfo = CSDiagnosticInfo.EmptyErrorInfo; +#nullable disable + internal PEAssemblySymbol(PEAssembly assembly, DocumentationProvider documentationProvider, bool isLinked, MetadataImportOptions importOptions) { Debug.Assert(assembly != null); @@ -280,5 +285,22 @@ internal PEModuleSymbol PrimaryModule } public override AssemblyMetadata GetMetadata() => _assembly.GetNonDisposableMetadata(); + +#nullable enable + internal DiagnosticInfo? GetCompilerFeatureRequiredDiagnostic() + { + if (_lazyCachedCompilerFeatureRequiredDiagnosticInfo == CSDiagnosticInfo.EmptyErrorInfo) + { + Interlocked.CompareExchange( + ref _lazyCachedCompilerFeatureRequiredDiagnosticInfo, + PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic(this, PrimaryModule, this.Assembly.Handle, CompilerFeatureRequiredFeatures.None, new MetadataDecoder(PrimaryModule)), + CSDiagnosticInfo.EmptyErrorInfo); + } + + return _lazyCachedCompilerFeatureRequiredDiagnosticInfo; + } + + public override bool HasUnsupportedMetadata + => GetCompilerFeatureRequiredDiagnostic()?.Code == (int)ErrorCode.ERR_UnsupportedCompilerFeature || base.HasUnsupportedMetadata; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEEventSymbol.cs index af90a53935133..d54359a94d388 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEEventSymbol.cs @@ -468,10 +468,30 @@ internal override UseSiteInfo GetUseSiteInfo() { UseSiteInfo result = new UseSiteInfo(primaryDependency); CalculateUseSiteDiagnostic(ref result); + deriveCompilerFeatureRequiredUseSiteInfo(ref result); _lazyCachedUseSiteInfo.Initialize(primaryDependency, result); } return _lazyCachedUseSiteInfo.ToUseSiteInfo(primaryDependency); + + void deriveCompilerFeatureRequiredUseSiteInfo(ref UseSiteInfo result) + { + var containingType = (PENamedTypeSymbol)ContainingType; + PEModuleSymbol containingPEModule = _containingType.ContainingPEModule; + var diag = PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic( + this, + containingPEModule, + Handle, + allowedFeatures: CompilerFeatureRequiredFeatures.None, + new MetadataDecoder(containingPEModule, containingType)); + + diag ??= containingType.GetCompilerFeatureRequiredDiagnostic(); + + if (diag != null) + { + result = new UseSiteInfo(diag); + } + } } internal override ObsoleteAttributeData ObsoleteAttributeData diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs index db882cdfa270e..85b42dd371845 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEFieldSymbol.cs @@ -590,10 +590,30 @@ internal override UseSiteInfo GetUseSiteInfo() { UseSiteInfo result = new UseSiteInfo(primaryDependency); CalculateUseSiteDiagnostic(ref result); + deriveCompilerFeatureRequiredUseSiteInfo(ref result); _lazyCachedUseSiteInfo.Initialize(primaryDependency, result); } return _lazyCachedUseSiteInfo.ToUseSiteInfo(primaryDependency); + + void deriveCompilerFeatureRequiredUseSiteInfo(ref UseSiteInfo result) + { + var containingType = (PENamedTypeSymbol)ContainingType; + PEModuleSymbol containingPEModule = _containingType.ContainingPEModule; + var diag = PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic( + this, + containingPEModule, + Handle, + allowedFeatures: CompilerFeatureRequiredFeatures.None, + new MetadataDecoder(containingPEModule, containingType)); + + diag ??= containingType.GetCompilerFeatureRequiredDiagnostic(); + + if (diag != null) + { + result = new UseSiteInfo(diag); + } + } } internal override ObsoleteAttributeData ObsoleteAttributeData diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs index 6055a69d842ba..0a55b53a0fc3f 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs @@ -1358,6 +1358,7 @@ internal override UseSiteInfo GetUseSiteInfo() CalculateUseSiteDiagnostic(ref result); var diagnosticInfo = result.DiagnosticInfo; + MergeUseSiteDiagnostics(ref diagnosticInfo, DeriveCompilerFeatureRequiredDiagnostic()); EnsureTypeParametersAreLoaded(ref diagnosticInfo); if (diagnosticInfo == null && GetUnmanagedCallersOnlyAttributeData(forceComplete: true) is UnmanagedCallersOnlyAttributeData data) { @@ -1380,6 +1381,44 @@ internal override UseSiteInfo GetUseSiteInfo() return GetCachedUseSiteInfo(); } + private DiagnosticInfo DeriveCompilerFeatureRequiredDiagnostic() + { + var containingModule = _containingType.ContainingPEModule; + var decoder = new MetadataDecoder(containingModule, this); + var diag = PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic(this, containingModule, Handle, allowedFeatures: MethodKind == MethodKind.Constructor ? CompilerFeatureRequiredFeatures.RequiredMembers : CompilerFeatureRequiredFeatures.None, decoder); + + if (diag != null) + { + return diag; + } + + diag = Signature.ReturnParam.DeriveCompilerFeatureRequiredDiagnostic(decoder); + if (diag != null) + { + return diag; + } + + foreach (var param in Parameters) + { + diag = ((PEParameterSymbol)param).DeriveCompilerFeatureRequiredDiagnostic(decoder); + if (diag != null) + { + return diag; + } + } + + foreach (var typeParam in TypeParameters) + { + diag = ((PETypeParameterSymbol)typeParam).DeriveCompilerFeatureRequiredDiagnostic(decoder); + if (diag != null) + { + return diag; + } + } + + return _containingType.GetCompilerFeatureRequiredDiagnostic(); + } + private UseSiteInfo GetCachedUseSiteInfo() { return (_uncommonFields?._lazyCachedUseSiteInfo ?? default).ToUseSiteInfo(PrimaryDependency); diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs index 82ad9299e0433..c7aba5ec51747 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEModuleSymbol.cs @@ -102,6 +102,10 @@ private enum NullableMemberMetadata private NullableMemberMetadata _lazyNullableMemberMetadata; +#nullable enable + private DiagnosticInfo? _lazyCachedCompilerFeatureRequiredDiagnosticInfo = CSDiagnosticInfo.EmptyErrorInfo; +#nullable disable + internal PEModuleSymbol(PEAssemblySymbol assemblySymbol, PEModule module, MetadataImportOptions importOptions, int ordinal) : this((AssemblySymbol)assemblySymbol, module, importOptions, ordinal) { @@ -755,5 +759,22 @@ internal bool ShouldDecodeNullableAttributes(Symbol symbol) return false; } + +#nullable enable + internal DiagnosticInfo? GetCompilerFeatureRequiredDiagnostic() + { + if (_lazyCachedCompilerFeatureRequiredDiagnosticInfo == CSDiagnosticInfo.EmptyErrorInfo) + { + Interlocked.CompareExchange( + ref _lazyCachedCompilerFeatureRequiredDiagnosticInfo, + PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic(this, this, Token, CompilerFeatureRequiredFeatures.None, new MetadataDecoder(this)), + CSDiagnosticInfo.EmptyErrorInfo); + } + + return _lazyCachedCompilerFeatureRequiredDiagnosticInfo ?? (_assemblySymbol as PEAssemblySymbol)?.GetCompilerFeatureRequiredDiagnostic(); + } + + public override bool HasUnsupportedMetadata + => GetCompilerFeatureRequiredDiagnostic()?.Code == (int)ErrorCode.ERR_UnsupportedCompilerFeature || base.HasUnsupportedMetadata; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs index fc2580001a927..74dfe4e540be5 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.cs @@ -199,7 +199,7 @@ internal static PENamedTypeSymbol Create( if (mrEx != null) { - result._lazyCachedUseSiteInfo.Initialize(new CSDiagnosticInfo(ErrorCode.ERR_BogusType, result)); + result._lazyCachedUseSiteInfo.Initialize(result.DeriveCompilerFeatureRequiredDiagnostic() ?? new CSDiagnosticInfo(ErrorCode.ERR_BogusType, result)); } return result; @@ -261,7 +261,7 @@ internal static PENamedTypeSymbol Create( if (mrEx != null || metadataArity < containerMetadataArity) { - result._lazyCachedUseSiteInfo.Initialize(new CSDiagnosticInfo(ErrorCode.ERR_BogusType, result)); + result._lazyCachedUseSiteInfo.Initialize(result.DeriveCompilerFeatureRequiredDiagnostic() ?? new CSDiagnosticInfo(ErrorCode.ERR_BogusType, result)); } return result; @@ -331,7 +331,7 @@ private PENamedTypeSymbol( if (makeBad) { - _lazyCachedUseSiteInfo.Initialize(new CSDiagnosticInfo(ErrorCode.ERR_BogusType, this)); + _lazyCachedUseSiteInfo.Initialize(DeriveCompilerFeatureRequiredDiagnostic() ?? new CSDiagnosticInfo(ErrorCode.ERR_BogusType, this)); } } @@ -2024,7 +2024,14 @@ internal override UseSiteInfo GetUseSiteInfo() protected virtual DiagnosticInfo GetUseSiteDiagnosticImpl() { - DiagnosticInfo diagnostic = null; + // GetCompilerFeatureRequiredDiagnostic depends on UnsupportedCompilerFeature being the highest priority diagnostic, or it will return incorrect + // results and assert in Debug mode. + DiagnosticInfo diagnostic = DeriveCompilerFeatureRequiredDiagnostic(); + + if (diagnostic != null) + { + return diagnostic; + } if (!MergeUseSiteDiagnostics(ref diagnostic, CalculateUseSiteDiagnostic())) { @@ -2060,6 +2067,45 @@ protected virtual DiagnosticInfo GetUseSiteDiagnosticImpl() return diagnostic; } +#nullable enable + internal DiagnosticInfo? GetCompilerFeatureRequiredDiagnostic() + { + var useSiteInfo = GetUseSiteInfo(); + if (useSiteInfo.DiagnosticInfo is { Code: (int)ErrorCode.ERR_UnsupportedCompilerFeature } diag) + { + return diag; + } + + Debug.Assert(DeriveCompilerFeatureRequiredDiagnostic() is null); + return null; + } + + private DiagnosticInfo? DeriveCompilerFeatureRequiredDiagnostic() + { + var decoder = new MetadataDecoder(ContainingPEModule, this); + var diag = PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic(this, ContainingPEModule, Handle, allowedFeatures: IsRefLikeType ? CompilerFeatureRequiredFeatures.RefStructs : CompilerFeatureRequiredFeatures.None, decoder); + + if (diag != null) + { + return diag; + } + + foreach (var typeParameter in TypeParameters) + { + diag = ((PETypeParameterSymbol)typeParameter).DeriveCompilerFeatureRequiredDiagnostic(decoder); + + if (diag != null) + { + return diag; + } + } + + return ContainingType is PENamedTypeSymbol containingType + ? containingType.GetCompilerFeatureRequiredDiagnostic() + : ContainingPEModule.GetCompilerFeatureRequiredDiagnostic(); + } +#nullable disable + internal string DefaultMemberName { get diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs index 1a0280d0473e5..2cd953f24778c 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEParameterSymbol.cs @@ -1068,5 +1068,25 @@ public sealed override bool Equals(Symbol other, TypeCompareKind compareKind) nps.Equals(this, compareKind) : base.Equals(other, compareKind); } + +#nullable enable + internal DiagnosticInfo? DeriveCompilerFeatureRequiredDiagnostic(MetadataDecoder decoder) + => PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic(this, (PEModuleSymbol)ContainingModule, Handle, allowedFeatures: CompilerFeatureRequiredFeatures.None, decoder); + + public override bool HasUnsupportedMetadata + { + get + { + var containingModule = (PEModuleSymbol)ContainingModule; + var decoder = ContainingSymbol switch + { + PEMethodSymbol method => new MetadataDecoder(containingModule, method), + PEPropertySymbol => new MetadataDecoder(containingModule, (PENamedTypeSymbol)ContainingType), + _ => throw ExceptionUtilities.UnexpectedValue(this.ContainingSymbol.Kind) + }; + + return DeriveCompilerFeatureRequiredDiagnostic(decoder) is { Code: (int)ErrorCode.ERR_UnsupportedCompilerFeature } || base.HasUnsupportedMetadata; + } + } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs index 26238a22178f2..8e87be1f8f865 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs @@ -784,10 +784,42 @@ internal override UseSiteInfo GetUseSiteInfo() { var result = new UseSiteInfo(primaryDependency); CalculateUseSiteDiagnostic(ref result); + var diag = deriveCompilerFeatureRequiredUseSiteInfo(); + MergeUseSiteDiagnostics(ref diag, result.DiagnosticInfo); + result = result.AdjustDiagnosticInfo(diag); _lazyCachedUseSiteInfo.Initialize(primaryDependency, result); } return _lazyCachedUseSiteInfo.ToUseSiteInfo(primaryDependency); + + DiagnosticInfo deriveCompilerFeatureRequiredUseSiteInfo() + { + var containingType = (PENamedTypeSymbol)ContainingType; + PEModuleSymbol containingPEModule = _containingType.ContainingPEModule; + var decoder = new MetadataDecoder(containingPEModule, containingType); + var diag = PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic( + this, + containingPEModule, + Handle, + allowedFeatures: CompilerFeatureRequiredFeatures.None, + decoder); + + if (diag != null) + { + return diag; + } + + foreach (var param in Parameters) + { + diag = ((PEParameterSymbol)param).DeriveCompilerFeatureRequiredDiagnostic(decoder); + if (diag != null) + { + return diag; + } + } + + return containingType.GetCompilerFeatureRequiredDiagnostic(); + } } internal override ObsoleteAttributeData ObsoleteAttributeData diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs index 9c1cd3c683066..147b7b07f8bc1 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.cs @@ -165,7 +165,7 @@ private ImmutableArray GetDeclaredConstraintTypes(ConsList< if (constraints.Count > 0) { var symbolsBuilder = ArrayBuilder.GetInstance(); - MetadataDecoder tokenDecoder = GetDecoderForConstraintTypes(moduleSymbol); + MetadataDecoder tokenDecoder = GetDecoder(moduleSymbol); TypeWithAnnotations bestObjectConstraint = default; @@ -246,7 +246,7 @@ private ImmutableArray GetDeclaredConstraintTypes(ConsList< return _lazyDeclaredConstraintTypes; } - private MetadataDecoder GetDecoderForConstraintTypes(PEModuleSymbol moduleSymbol) + private MetadataDecoder GetDecoder(PEModuleSymbol moduleSymbol) { MetadataDecoder tokenDecoder; if (_containingSymbol.Kind == SymbolKind.Method) @@ -534,7 +534,7 @@ internal override bool? IsNotNullable { // We must have filtered out some Object constraints, lets calculate nullability from them. var symbolsBuilder = ArrayBuilder.GetInstance(); - MetadataDecoder tokenDecoder = GetDecoderForConstraintTypes(moduleSymbol); + MetadataDecoder tokenDecoder = GetDecoder(moduleSymbol); bool hasUnmanagedModreqPattern = false; var metadataReader = module.MetadataReader; @@ -705,5 +705,18 @@ private NamedTypeSymbol GetDefaultBaseType() { get { return null; } } + +#nullable enable + internal DiagnosticInfo? DeriveCompilerFeatureRequiredDiagnostic(MetadataDecoder decoder) + => PEUtilities.DeriveCompilerFeatureRequiredAttributeDiagnostic(this, (PEModuleSymbol)ContainingModule, Handle, CompilerFeatureRequiredFeatures.None, decoder); + + public override bool HasUnsupportedMetadata + { + get + { + var containingModule = (PEModuleSymbol)ContainingModule; + return DeriveCompilerFeatureRequiredDiagnostic(GetDecoder(containingModule)) is { Code: (int)ErrorCode.ERR_UnsupportedCompilerFeature } || base.HasUnsupportedMetadata; + } + } } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEUtilities.cs b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEUtilities.cs new file mode 100644 index 0000000000000..4d88aa5c074d3 --- /dev/null +++ b/src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEUtilities.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Reflection.Metadata; + +namespace Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE; + +internal static class PEUtilities +{ + internal static DiagnosticInfo? DeriveCompilerFeatureRequiredAttributeDiagnostic(Symbol symbol, PEModuleSymbol module, EntityHandle handle, CompilerFeatureRequiredFeatures allowedFeatures, MetadataDecoder decoder) + { + string? disallowedFeature = module.Module.GetFirstUnsupportedCompilerFeatureFromToken(handle, decoder, allowedFeatures); + return disallowedFeature != null + ? // '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + new CSDiagnosticInfo(ErrorCode.ERR_UnsupportedCompilerFeature, symbol, disallowedFeature) + : null; + } +} diff --git a/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs index 5b51c89354a93..b32dbc1a67287 100644 --- a/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs @@ -1056,22 +1056,16 @@ static bool isGenericMethod([DisallowNull] MethodSymbol? method) #nullable disable /// - /// Return error code that has highest priority while calculating use site error for this symbol. + /// Returns true if the error code is highest priority while calculating use site error for this symbol. /// - protected override int HighestPriorityUseSiteError - { - get - { - return (int)ErrorCode.ERR_BindToBogus; - } - } + protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code) => code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BindToBogus; public sealed override bool HasUnsupportedMetadata { get { DiagnosticInfo info = GetUseSiteInfo().DiagnosticInfo; - return (object)info != null && info.Code == (int)ErrorCode.ERR_BindToBogus; + return (object)info != null && info.Code is (int)ErrorCode.ERR_BindToBogus or (int)ErrorCode.ERR_UnsupportedCompilerFeature; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/ParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/ParameterSymbol.cs index 60d51dd0d52af..67dea1a0d59b3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/ParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/ParameterSymbol.cs @@ -420,21 +420,15 @@ internal sealed override ObsoleteAttributeData? ObsoleteAttributeData /// internal abstract bool HasInterpolatedStringHandlerArgumentError { get; } - protected sealed override int HighestPriorityUseSiteError - { - get - { - return (int)ErrorCode.ERR_BogusType; - } - } + protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code) => code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BogusType; - public sealed override bool HasUnsupportedMetadata + public override bool HasUnsupportedMetadata { get { UseSiteInfo info = default; DeriveUseSiteInfoFromParameter(ref info, this); - return info.DiagnosticInfo?.Code == (int)ErrorCode.ERR_BogusType; + return info.DiagnosticInfo?.Code is (int)ErrorCode.ERR_BogusType or (int)ErrorCode.ERR_UnsupportedCompilerFeature; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/PropertySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/PropertySymbol.cs index 04078ac60e638..245c42e1b0d21 100644 --- a/src/Compilers/CSharp/Portable/Symbols/PropertySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/PropertySymbol.cs @@ -400,22 +400,16 @@ internal bool CalculateUseSiteDiagnostic(ref UseSiteInfo result) } /// - /// Return error code that has highest priority while calculating use site error for this symbol. + /// Returns true if the error code is highest priority while calculating use site error for this symbol. /// - protected override int HighestPriorityUseSiteError - { - get - { - return (int)ErrorCode.ERR_BindToBogus; - } - } + protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code) => code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BindToBogus; public sealed override bool HasUnsupportedMetadata { get { DiagnosticInfo info = GetUseSiteInfo().DiagnosticInfo; - return (object)info != null && info.Code == (int)ErrorCode.ERR_BindToBogus; + return (object)info != null && info.Code is (int)ErrorCode.ERR_BindToBogus or (int)ErrorCode.ERR_UnsupportedCompilerFeature; } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/FieldSymbolWithAttributesAndModifiers.cs b/src/Compilers/CSharp/Portable/Symbols/Source/FieldSymbolWithAttributesAndModifiers.cs index c3dffe96baddf..9ef9d8c5f4828 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/FieldSymbolWithAttributesAndModifiers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/FieldSymbolWithAttributesAndModifiers.cs @@ -159,7 +159,7 @@ internal sealed override ObsoleteAttributeData ObsoleteAttributeData } } - internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); var diagnostics = (BindingDiagnosticBag)arguments.Diagnostics; diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs index edddf9d51e120..3380a2b8eef1b 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceAssemblySymbol.cs @@ -2326,7 +2326,7 @@ AttributeLocation IAttributeTargetSymbol.AllowedAttributeLocations } } - internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { DecodeWellKnownAttribute(ref arguments, arguments.Index, isFromNetModule: false); } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs index f2d00eca5a103..56028d19ad2d3 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceComplexParameterSymbol.cs @@ -673,7 +673,7 @@ internal override (CSharpAttributeData?, BoundAttribute?) EarlyDecodeWellKnownAt } #nullable disable - internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs index 1af5b62fe17ab..a8428f790e6d5 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceEventSymbol.cs @@ -285,7 +285,7 @@ internal override ObsoleteAttributeData? ObsoleteAttributeData } } - internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { var attribute = arguments.Attribute; Debug.Assert(!attribute.HasErrors); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs index 27f03f3938c9f..289646dbb5da8 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceFieldSymbol.cs @@ -110,7 +110,7 @@ public override NamedTypeSymbol ContainingType } } - internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); Debug.Assert(arguments.Diagnostics is BindingDiagnosticBag); @@ -126,7 +126,7 @@ internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttrib } else { - base.DecodeWellKnownAttribute(ref arguments); + base.DecodeWellKnownAttributeImpl(ref arguments); } } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs index e3102401bc21e..257918705685d 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs @@ -466,7 +466,7 @@ internal sealed override ImmutableArray GetAppliedConditionalSymbols() return data != null ? data.ConditionalSymbols : ImmutableArray.Empty; } - internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert(!arguments.Attribute.HasErrors); Debug.Assert(arguments.SymbolPart == AttributeLocation.None || arguments.SymbolPart == AttributeLocation.Return); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs index 283ee801f565f..d075530f97e93 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceModuleSymbol.cs @@ -498,7 +498,7 @@ private ModuleWellKnownAttributeData GetDecodedWellKnownAttributeData() return (ModuleWellKnownAttributeData)attributesBag.DecodedWellKnownAttributeData; } - internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs index 7f62bbe43c20d..ce90ac3dff23d 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs @@ -1042,7 +1042,7 @@ internal override ObsoleteAttributeData ObsoleteAttributeData } } - internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); var diagnostics = (BindingDiagnosticBag)arguments.Diagnostics; diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs index 411f55d04eaac..15bc182ad78ef 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourcePropertySymbolBase.cs @@ -1243,7 +1243,7 @@ internal override ObsoleteAttributeData ObsoleteAttributeData } } - internal override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert(arguments.AttributeSyntaxOpt != null); diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/SourceTypeParameterSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Source/SourceTypeParameterSymbol.cs index 7ae3bfd1e8c50..ab763392e17dd 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/SourceTypeParameterSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/SourceTypeParameterSymbol.cs @@ -415,7 +415,7 @@ internal byte GetSynthesizedNullableAttributeValue() return NullableAnnotationExtensions.ObliviousAttributeValue; } - internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); Debug.Assert(arguments.Diagnostics is BindingDiagnosticBag); @@ -424,13 +424,9 @@ internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttrib Debug.Assert(!attribute.HasErrors); Debug.Assert(arguments.SymbolPart == AttributeLocation.None); - if (attribute.IsTargetAttribute(this, AttributeDescription.NullableAttribute)) - { - // NullableAttribute should not be set explicitly. - ((BindingDiagnosticBag)arguments.Diagnostics).Add(ErrorCode.ERR_ExplicitNullableAttribute, arguments.AttributeSyntaxOpt.Location); - } + ReportExplicitUseOfReservedAttributes(in arguments, ReservedAttributes.NullableAttribute); - base.DecodeWellKnownAttribute(ref arguments); + base.DecodeWellKnownAttributeImpl(ref arguments); } protected bool? CalculateReferenceTypeConstraintIsNullable(TypeParameterConstraintKind constraints) diff --git a/src/Compilers/CSharp/Portable/Symbols/Symbol.cs b/src/Compilers/CSharp/Portable/Symbols/Symbol.cs index a58ea6f67df15..4f1a4d2545fea 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Symbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Symbol.cs @@ -939,16 +939,10 @@ protected AssemblySymbol PrimaryDependency } /// - /// Return error code that has highest priority while calculating use site error for this symbol. + /// Returns true if the error code is the highest priority while calculating use site error for this symbol. /// Supposed to be ErrorCode, but it causes inconsistent accessibility error. /// - protected virtual int HighestPriorityUseSiteError - { - get - { - return int.MaxValue; - } - } + protected virtual bool IsHighestPriorityUseSiteErrorCode(int code) => true; /// /// Indicates that this symbol uses metadata that cannot be supported by the language. @@ -987,7 +981,7 @@ internal bool MergeUseSiteDiagnostics(ref DiagnosticInfo result, DiagnosticInfo return false; } - if (info.Severity == DiagnosticSeverity.Error && (info.Code == HighestPriorityUseSiteError || HighestPriorityUseSiteError == Int32.MaxValue)) + if (info.Severity == DiagnosticSeverity.Error && IsHighestPriorityUseSiteErrorCode(info.Code)) { // this error is final, no other error can override it: result = info; @@ -1122,7 +1116,6 @@ internal bool DeriveUseSiteInfoFromParameters(ref UseSiteInfo re return false; } - [Flags] internal enum AllowedRequiredModifierType { diff --git a/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs b/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs index 472f6df41f379..153bdb1e09f92 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Symbol_Attributes.cs @@ -209,7 +209,23 @@ internal static bool EarlyDecodeDeprecatedOrExperimentalOrObsoleteAttribute( /// this (base) method. /// /// - internal virtual void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) +#nullable enable + protected void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + { + Debug.Assert(arguments.Diagnostics.DiagnosticBag is not null); + Debug.Assert(arguments.AttributeSyntaxOpt is not null); + if (arguments.Attribute.IsTargetAttribute(this, AttributeDescription.CompilerFeatureRequiredAttribute)) + { + // Do not use '{FullName}'. This is reserved for compiler usage. + arguments.Diagnostics.DiagnosticBag.Add(ErrorCode.ERR_ExplicitReservedAttr, arguments.AttributeSyntaxOpt.Location, AttributeDescription.CompilerFeatureRequiredAttribute.FullName); + return; + } + + DecodeWellKnownAttributeImpl(ref arguments); + } +#nullable disable + + protected virtual void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { } @@ -654,7 +670,7 @@ private void EarlyDecodeWellKnownAttributeTypes(ImmutableArray } /// - /// This method validates attribute usage for each bound attribute and calls + /// This method validates attribute usage for each bound attribute and calls /// on attributes with valid attribute usage. /// This method is called by the binder when it is finished binding a set of attributes on the symbol so that /// the symbol can extract data from the attribute arguments and potentially perform validation specific to diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs index 156c5ea333769..6aa06f16efe02 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/SynthesizedBackingFieldSymbol.cs @@ -63,7 +63,7 @@ internal override TypeWithAnnotations GetFieldType(ConsList fieldsB internal override bool HasPointerType => _property.HasPointerType; - internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttributeArguments arguments) + protected sealed override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttributeArguments arguments) { Debug.Assert((object)arguments.AttributeSyntaxOpt != null); Debug.Assert(arguments.Diagnostics is BindingDiagnosticBag); @@ -79,7 +79,7 @@ internal sealed override void DecodeWellKnownAttribute(ref DecodeWellKnownAttrib } else { - base.DecodeWellKnownAttribute(ref arguments); + base.DecodeWellKnownAttributeImpl(ref arguments); } } diff --git a/src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs index 96d2962bd7362..c37955f2fb5f6 100644 --- a/src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs @@ -517,23 +517,18 @@ internal Microsoft.Cci.PrimitiveTypeCode PrimitiveTypeCode #region Use-Site Diagnostics /// - /// Return error code that has highest priority while calculating use site error for this symbol. + /// Returns true if the error code is highest priority while calculating use site error for this symbol. /// - protected override int HighestPriorityUseSiteError - { - get - { - return (int)ErrorCode.ERR_BogusType; - } - } + protected sealed override bool IsHighestPriorityUseSiteErrorCode(int code) + => code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BogusType; - public sealed override bool HasUnsupportedMetadata + public override bool HasUnsupportedMetadata { get { DiagnosticInfo info = GetUseSiteInfo().DiagnosticInfo; - return (object)info != null && info.Code == (int)ErrorCode.ERR_BogusType; + return (object)info != null && info.Code is (int)ErrorCode.ERR_UnsupportedCompilerFeature or (int)ErrorCode.ERR_BogusType; } } diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 7bf2d09a42d16..7af6b95918e15 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -1452,6 +1452,11 @@ {0} má atribut UnmanagedCallersOnly a nedá se převést na typ delegáta. Pro tuto metodu získejte ukazatel na funkci. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Vzory seznamů se nedají používat pro hodnotu typu {0}. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 15187439c4477..a8c534d869d06 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -1452,6 +1452,11 @@ "{0}" ist mit dem Attribut "UnmanagedCallersOnly" versehen und kann nicht in einen Delegattyp konvertiert werden. Rufen Sie einen Funktionszeiger auf diese Methode ab. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Listenmuster dürfen nicht für einen Wert vom Typ „{0}“ verwendet werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 9e2f84a5663d0..d91175bafc30c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -1452,6 +1452,11 @@ ' {0} ' tiene un atributo ' UnmanagedCallersOnly ' y no se puede convertir en un tipo de delegado. Obtenga un puntero de función a este método. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. No se pueden utilizar patrones de lista para un valor de tipo "{0}". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 51dd4d16b9387..86da73c01ef1e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -1452,6 +1452,11 @@ '{0}' est attribué avec 'UnmanagedCallersOnly' et ne peut pas être converti en type délégué. Obtenez un pointeur de fonction vers cette méthode. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Les modèles de liste ne peuvent pas être utilisés pour une valeur de type '{0}'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 025c0559efc20..ba7e71a235f04 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -1452,6 +1452,11 @@ '{0}', a cui è assegnato l'attributo 'UnmanagedCallersOnly', non può essere convertito in un tipo delegato. Ottenere un puntatore a funzione per questo metodo. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Non è possibile usare i modelli di elenco per un valore di tipo '{0}'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index d203290e0e76f..2096046e933f2 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -1452,6 +1452,11 @@ '{0}' は 'UnmanagedCallersOnly' 属性が設定されているため、デリゲート型に変換できません。このメソッドへの関数ポインターを取得してください。 UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. リスト パターンは、'{0}' 型の値に使用されない可能性があります。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index f04105cc99ac0..d27976def10f9 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -1452,6 +1452,11 @@ '{0}'에는 'UnmanagedCallersOnly' 특성이 지정되어 있으며 이 항목은 대리자 형식으로 변환할 수 없습니다. 이 메서드에 대한 함수 포인터를 가져오세요. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. 목록 패턴은 '{0}' 형식 값에 사용할 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index c46455c255075..8c456dbbca165 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -1452,6 +1452,11 @@ Element „{0}” ma atrybut „UnmanagedCallersOnly” i nie można go przekonwertować na typ delegowany. Uzyskaj wskaźnik funkcji do tej metody. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Wzorców list nie można używać na potrzeby wartości typu „{0}”. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index aa08fce2a0f32..ed3183747d378 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -1452,6 +1452,11 @@ '{0}' foi atribuído com 'UnmanagedCallersOnly' e não pode ser convertido em um tipo delegado. Obtenha um ponteiro de função para esse método. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Os padrões de lista não podem ser usados para um valor do tipo '{0}'. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index de6db896a5cb6..8a0a03c42450a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -1452,6 +1452,11 @@ "{0}" имеет атрибут "UnmanagedCallersOnly" и не может быть преобразован в тип делегата. Получите указатель на функцию для этого метода. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Шаблоны списка не могут использоваться для значений типа "{0}". diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 821bd0470140c..f1fed19842712 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -1452,6 +1452,11 @@ '{0}', 'UnmanagedCallersOnly' özniteliğine sahip ve temsilci türüne dönüştürülemez. Bu yöntem için bir işlev işaretçisi edinin. UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. Liste desenleri, '{0}' türünde bir değer için kullanılamaz. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 6e88ee65d4277..969a491431f5e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -1452,6 +1452,11 @@ “{0}”使用 "UnmanagedCallersOnly" 进行特性化,无法转换为委托类型。请获取指向此方法的函数指针。 UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. 列表模式不能用于类型为“{0}”的值。 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 36bd4facdadd6..02b7dd1fbb1be 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -1452,6 +1452,11 @@ '{0}' 使用 'UnmanagedCallersOnly' 屬性化,因此無法轉換為委派類型。取得此方法的函式指標。 UnmanagedCallersOnly is not localizable. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the C# compiler. + + List patterns may not be used for a value of type '{0}'. 類型 '{0}' 的值不可使用清單模式。 diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/CSharpCompilerFeatureRequiredTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/CSharpCompilerFeatureRequiredTests.cs new file mode 100644 index 0000000000000..1de6ce3a0be82 --- /dev/null +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/CSharpCompilerFeatureRequiredTests.cs @@ -0,0 +1,692 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Linq; +using Microsoft.CodeAnalysis.CodeGen; +using Microsoft.CodeAnalysis.CSharp.Symbols; +using Microsoft.CodeAnalysis.CSharp.Test.Utilities; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.UnitTests; +using Xunit; + +namespace Microsoft.CodeAnalysis.CSharp.UnitTests.Symbols; + +public class CSharpCompilerFeatureRequiredTests : BaseCompilerFeatureRequiredTests +{ + private class CompilerFeatureRequiredTests_CSharp : CSharpTestBase { } + + private readonly CompilerFeatureRequiredTests_CSharp _csharpTest = new CompilerFeatureRequiredTests_CSharp(); + + protected override CSharpTestSource GetUsage() => """ + #pragma warning disable 168 // Unused local + OnType onType; + OnType.M(); + OnMethod.M(); + OnMethodReturn.M(); + OnParameter.M(1); + _ = OnField.Field; + OnProperty.Property = 1; + _ = OnProperty.Property; + OnPropertySetter.Property = 1; + _ = OnPropertySetter.Property; + OnPropertyGetter.Property = 1; + _ = OnPropertyGetter.Property; + OnEvent.Event += () => {}; + OnEvent.Event -= () => {}; + OnEventAdder.Event += () => {}; + OnEventAdder.Event -= () => {}; + OnEventRemover.Event += () => {}; + OnEventRemover.Event -= () => {}; + OnEnum onEnum; + _ = OnEnumMember.A; + OnClassTypeParameter onClassTypeParameter; + OnMethodTypeParameter.M(); + OnDelegateType onDelegateType; + OnIndexedPropertyParameter.set_Property(1, 1); + _ = OnIndexedPropertyParameter.get_Property(1); + new OnThisIndexerParameter()[1] = 1; + _ = new OnThisIndexerParameter()[1]; + """; + + internal override string VisualizeRealIL(IModuleSymbol peModule, CompilationTestData.MethodData methodData, IReadOnlyDictionary markers, bool areLocalsZeroed) + { + return _csharpTest.VisualizeRealIL(peModule, methodData, markers, areLocalsZeroed); + } + + protected override CSharpCompilation CreateCompilationWithIL(CSharpTestSource source, string ilSource) + { + return CSharpTestBase.CreateCompilationWithIL(source, ilSource); + } + + protected override CSharpCompilation CreateCompilation(CSharpTestSource source, MetadataReference[] references) + { + return CSharpTestBase.CreateCompilation(source, references); + } + + protected override CompilationVerifier CompileAndVerify(CSharpCompilation compilation) + { + return _csharpTest.CompileAndVerify(compilation); + } + + protected override void AssertNormalErrors(CSharpCompilation comp) + { + comp.VerifyDiagnostics( + // (2,1): error CS9512: 'OnType' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType onType; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnType").WithArguments("OnType", "test").WithLocation(2, 1), + // (3,1): error CS9512: 'OnType' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnType").WithArguments("OnType", "test").WithLocation(3, 1), + // (3,8): error CS9512: 'OnType' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnType", "test").WithLocation(3, 8), + // (4,10): error CS9512: 'OnMethod.M()' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethod.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnMethod.M()", "test").WithLocation(4, 10), + // (5,16): error CS9512: 'void' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodReturn.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("void", "test").WithLocation(5, 16), + // (6,13): error CS9512: 'int' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnParameter.M(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("int", "test").WithLocation(6, 13), + // (7,13): error CS9512: 'OnField.Field' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnField.Field; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Field").WithArguments("OnField.Field", "test").WithLocation(7, 13), + // (8,12): error CS9512: 'OnProperty.Property' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnProperty.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnProperty.Property", "test").WithLocation(8, 12), + // (9,16): error CS9512: 'OnProperty.Property' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnProperty.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnProperty.Property", "test").WithLocation(9, 16), + // (10,18): error CS9512: 'OnPropertySetter.Property.set' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertySetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnPropertySetter.Property.set", "test").WithLocation(10, 18), + // (13,22): error CS9512: 'OnPropertyGetter.Property.get' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertyGetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnPropertyGetter.Property.get", "test").WithLocation(13, 22), + // (14,9): error CS9512: 'OnEvent.Event' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnEvent.Event", "test").WithLocation(14, 9), + // (15,9): error CS9512: 'OnEvent.Event' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnEvent.Event", "test").WithLocation(15, 9), + // (20,1): error CS9512: 'OnEnum' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEnum onEnum; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEnum").WithArguments("OnEnum", "test").WithLocation(20, 1), + // (21,18): error CS9512: 'OnEnumMember.A' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnEnumMember.A; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "A").WithArguments("OnEnumMember.A", "test").WithLocation(21, 18), + // (22,1): error CS9512: 'T' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnClassTypeParameter onClassTypeParameter; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnClassTypeParameter").WithArguments("T", "test").WithLocation(22, 1), + // (23,23): error CS9512: 'T' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodTypeParameter.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("T", "test").WithLocation(23, 23), + // (24,1): error CS9512: 'OnDelegateType' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnDelegateType onDelegateType; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnDelegateType").WithArguments("OnDelegateType", "test").WithLocation(24, 1), + // (25,28): error CS9512: 'int' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnIndexedPropertyParameter.set_Property(1, 1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "set_Property").WithArguments("int", "test").WithLocation(25, 28), + // (26,32): error CS9512: 'int' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnIndexedPropertyParameter.get_Property(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "get_Property").WithArguments("int", "test").WithLocation(26, 32), + // (27,1): error CS9512: 'int' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // new OnThisIndexerParameter()[1] = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "new OnThisIndexerParameter()[1]").WithArguments("int", "test").WithLocation(27, 1), + // (28,5): error CS9512: 'int' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = new OnThisIndexerParameter()[1]; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "new OnThisIndexerParameter()[1]").WithArguments("int", "test").WithLocation(28, 5) + ); + + var onType = comp.GetTypeByMetadataName("OnType"); + Assert.True(onType!.HasUnsupportedMetadata); + Assert.True(onType.GetMember("M").HasUnsupportedMetadata); + + var onMethod = comp.GetTypeByMetadataName("OnMethod"); + Assert.False(onMethod!.HasUnsupportedMetadata); + Assert.True(onMethod.GetMember("M").HasUnsupportedMetadata); + + var onMethodReturn = comp.GetTypeByMetadataName("OnMethodReturn"); + Assert.False(onMethodReturn!.HasUnsupportedMetadata); + Assert.True(onMethodReturn.GetMember("M").HasUnsupportedMetadata); + + var onParameter = comp.GetTypeByMetadataName("OnParameter"); + Assert.False(onParameter!.HasUnsupportedMetadata); + var onParameterMethod = onParameter.GetMember("M"); + Assert.True(onParameterMethod.HasUnsupportedMetadata); + Assert.True(onParameterMethod.Parameters[0].HasUnsupportedMetadata); + + var onField = comp.GetTypeByMetadataName("OnField"); + Assert.False(onField!.HasUnsupportedMetadata); + Assert.True(onField.GetMember("Field").HasUnsupportedMetadata); + + var onProperty = comp.GetTypeByMetadataName("OnProperty"); + Assert.False(onProperty!.HasUnsupportedMetadata); + Assert.True(onProperty.GetMember("Property").HasUnsupportedMetadata); + + var onPropertyGetter = comp.GetTypeByMetadataName("OnPropertyGetter"); + Assert.False(onPropertyGetter!.HasUnsupportedMetadata); + var onPropertyGetterProperty = onPropertyGetter.GetMember("Property"); + Assert.False(onPropertyGetterProperty.HasUnsupportedMetadata); + Assert.False(onPropertyGetterProperty.SetMethod.HasUnsupportedMetadata); + Assert.True(onPropertyGetterProperty.GetMethod.HasUnsupportedMetadata); + + var onPropertySetter = comp.GetTypeByMetadataName("OnPropertySetter"); + Assert.False(onPropertySetter!.HasUnsupportedMetadata); + var onPropertySetterProperty = onPropertySetter.GetMember("Property"); + Assert.False(onPropertySetterProperty.HasUnsupportedMetadata); + Assert.True(onPropertySetterProperty.SetMethod.HasUnsupportedMetadata); + Assert.False(onPropertySetterProperty.GetMethod.HasUnsupportedMetadata); + + var onEvent = comp.GetTypeByMetadataName("OnEvent"); + Assert.False(onEvent!.HasUnsupportedMetadata); + Assert.True(onEvent.GetMember("Event").HasUnsupportedMetadata); + + var onEventAdder = comp.GetTypeByMetadataName("OnEventAdder"); + Assert.False(onEventAdder!.HasUnsupportedMetadata); + var onEventAdderEvent = onEventAdder.GetMember("Event"); + Assert.False(onEventAdderEvent.HasUnsupportedMetadata); + Assert.True(onEventAdderEvent.AddMethod!.HasUnsupportedMetadata); + Assert.False(onEventAdderEvent.RemoveMethod!.HasUnsupportedMetadata); + + var onEventRemover = comp.GetTypeByMetadataName("OnEventRemover"); + Assert.False(onEventRemover!.HasUnsupportedMetadata); + var onEventRemoverEvent = onEventRemover.GetMember("Event"); + Assert.False(onEventRemoverEvent.HasUnsupportedMetadata); + Assert.False(onEventRemoverEvent.AddMethod!.HasUnsupportedMetadata); + Assert.True(onEventRemoverEvent.RemoveMethod!.HasUnsupportedMetadata); + + var onEnum = comp.GetTypeByMetadataName("OnEnum"); + Assert.True(onEnum!.HasUnsupportedMetadata); + + var onEnumMember = comp.GetTypeByMetadataName("OnEnumMember"); + Assert.False(onEnumMember!.HasUnsupportedMetadata); + Assert.True(onEnumMember.GetMember("A").HasUnsupportedMetadata); + + var onClassTypeParameter = comp.GetTypeByMetadataName("OnClassTypeParameter`1"); + Assert.True(onClassTypeParameter!.HasUnsupportedMetadata); + Assert.True(onClassTypeParameter.TypeParameters[0].HasUnsupportedMetadata); + + var onMethodTypeParameter = comp.GetTypeByMetadataName("OnMethodTypeParameter"); + Assert.False(onMethodTypeParameter!.HasUnsupportedMetadata); + var onMethodTypeParameterMethod = onMethodTypeParameter.GetMember("M"); + Assert.True(onMethodTypeParameterMethod.HasUnsupportedMetadata); + Assert.True(onMethodTypeParameterMethod.TypeParameters[0].HasUnsupportedMetadata); + + var onDelegateType = comp.GetTypeByMetadataName("OnDelegateType"); + Assert.True(onDelegateType!.HasUnsupportedMetadata); + + var onIndexedPropertyParameter = comp.GetTypeByMetadataName("OnIndexedPropertyParameter"); + Assert.False(onIndexedPropertyParameter!.HasUnsupportedMetadata); + Assert.True(onIndexedPropertyParameter.GetMember("get_Property").Parameters[0].HasUnsupportedMetadata); + Assert.True(onIndexedPropertyParameter.GetMember("set_Property").Parameters[0].HasUnsupportedMetadata); + + var onThisParameterIndexer = comp.GetTypeByMetadataName("OnThisIndexerParameter"); + Assert.False(onThisParameterIndexer!.HasUnsupportedMetadata); + var indexer = onThisParameterIndexer.GetMember("this[]"); + Assert.True(indexer.HasUnsupportedMetadata); + Assert.True(indexer.Parameters[0].HasUnsupportedMetadata); + } + + protected override void AssertModuleErrors(CSharpCompilation comp, MetadataReference ilRef) + { + comp.VerifyDiagnostics( + // (2,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType onType; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnType").WithArguments("OnModule", "test").WithLocation(2, 1), + // (3,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnType").WithArguments("OnModule", "test").WithLocation(3, 1), + // (3,8): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnModule", "test").WithLocation(3, 8), + // (4,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethod.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnMethod").WithArguments("OnModule", "test").WithLocation(4, 1), + // (4,10): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethod.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnModule", "test").WithLocation(4, 10), + // (5,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodReturn.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnMethodReturn").WithArguments("OnModule", "test").WithLocation(5, 1), + // (5,16): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodReturn.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnModule", "test").WithLocation(5, 16), + // (6,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnParameter.M(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnParameter").WithArguments("OnModule", "test").WithLocation(6, 1), + // (6,13): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnParameter.M(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnModule", "test").WithLocation(6, 13), + // (7,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnField.Field; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnField").WithArguments("OnModule", "test").WithLocation(7, 5), + // (7,13): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnField.Field; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Field").WithArguments("OnModule", "test").WithLocation(7, 13), + // (8,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnProperty.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnProperty").WithArguments("OnModule", "test").WithLocation(8, 1), + // (8,12): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnProperty.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnModule", "test").WithLocation(8, 12), + // (9,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnProperty.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnProperty").WithArguments("OnModule", "test").WithLocation(9, 5), + // (9,16): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnProperty.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnModule", "test").WithLocation(9, 16), + // (10,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertySetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertySetter").WithArguments("OnModule", "test").WithLocation(10, 1), + // (10,18): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertySetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnModule", "test").WithLocation(10, 18), + // (11,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertySetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertySetter").WithArguments("OnModule", "test").WithLocation(11, 5), + // (11,22): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertySetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnModule", "test").WithLocation(11, 22), + // (12,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertyGetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertyGetter").WithArguments("OnModule", "test").WithLocation(12, 1), + // (12,18): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertyGetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnModule", "test").WithLocation(12, 18), + // (13,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertyGetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertyGetter").WithArguments("OnModule", "test").WithLocation(13, 5), + // (13,22): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertyGetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("OnModule", "test").WithLocation(13, 22), + // (14,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEvent").WithArguments("OnModule", "test").WithLocation(14, 1), + // (14,9): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnModule", "test").WithLocation(14, 9), + // (15,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEvent").WithArguments("OnModule", "test").WithLocation(15, 1), + // (15,9): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnModule", "test").WithLocation(15, 9), + // (16,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventAdder").WithArguments("OnModule", "test").WithLocation(16, 1), + // (16,14): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnModule", "test").WithLocation(16, 14), + // (17,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventAdder").WithArguments("OnModule", "test").WithLocation(17, 1), + // (17,14): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnModule", "test").WithLocation(17, 14), + // (18,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventRemover").WithArguments("OnModule", "test").WithLocation(18, 1), + // (18,16): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnModule", "test").WithLocation(18, 16), + // (19,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventRemover").WithArguments("OnModule", "test").WithLocation(19, 1), + // (19,16): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("OnModule", "test").WithLocation(19, 16), + // (20,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEnum onEnum; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEnum").WithArguments("OnModule", "test").WithLocation(20, 1), + // (21,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnEnumMember.A; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEnumMember").WithArguments("OnModule", "test").WithLocation(21, 5), + // (21,18): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnEnumMember.A; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "A").WithArguments("OnModule", "test").WithLocation(21, 18), + // (22,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnClassTypeParameter onClassTypeParameter; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnClassTypeParameter").WithArguments("OnModule", "test").WithLocation(22, 1), + // (23,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodTypeParameter.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnMethodTypeParameter").WithArguments("OnModule", "test").WithLocation(23, 1), + // (23,23): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodTypeParameter.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("OnModule", "test").WithLocation(23, 23), + // (24,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnDelegateType onDelegateType; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnDelegateType").WithArguments("OnModule", "test").WithLocation(24, 1), + // (25,1): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnIndexedPropertyParameter.set_Property(1, 1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnIndexedPropertyParameter").WithArguments("OnModule", "test").WithLocation(25, 1), + // (25,28): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnIndexedPropertyParameter.set_Property(1, 1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "set_Property").WithArguments("OnModule", "test").WithLocation(25, 28), + // (26,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnIndexedPropertyParameter.get_Property(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnIndexedPropertyParameter").WithArguments("OnModule", "test").WithLocation(26, 5), + // (26,32): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnIndexedPropertyParameter.get_Property(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "get_Property").WithArguments("OnModule", "test").WithLocation(26, 32), + // (27,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // new OnThisIndexerParameter()[1] = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("OnModule", "test").WithLocation(27, 5), + // (27,5): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // new OnThisIndexerParameter()[1] = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("OnModule", "test").WithLocation(27, 5), + // (28,9): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = new OnThisIndexerParameter()[1]; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("OnModule", "test").WithLocation(28, 9), + // (28,9): error CS9512: 'OnModule' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = new OnThisIndexerParameter()[1]; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("OnModule", "test").WithLocation(28, 9) + ); + + Assert.True(comp.GetReferencedAssemblySymbol(ilRef).Modules.Single().HasUnsupportedMetadata); + } + + protected override void AssertAssemblyErrors(CSharpCompilation comp, MetadataReference ilRef) + { + comp.VerifyDiagnostics( + // (2,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType onType; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnType").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(2, 1), + // (3,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnType").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(3, 1), + // (3,8): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnType.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(3, 8), + // (4,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethod.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnMethod").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(4, 1), + // (4,10): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethod.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(4, 10), + // (5,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodReturn.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnMethodReturn").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(5, 1), + // (5,16): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodReturn.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(5, 16), + // (6,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnParameter.M(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(6, 1), + // (6,13): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnParameter.M(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(6, 13), + // (7,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnField.Field; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnField").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(7, 5), + // (7,13): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnField.Field; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Field").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(7, 13), + // (8,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnProperty.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnProperty").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(8, 1), + // (8,12): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnProperty.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(8, 12), + // (9,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnProperty.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnProperty").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(9, 5), + // (9,16): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnProperty.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(9, 16), + // (10,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertySetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertySetter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(10, 1), + // (10,18): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertySetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(10, 18), + // (11,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertySetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertySetter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(11, 5), + // (11,22): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertySetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(11, 22), + // (12,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertyGetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertyGetter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(12, 1), + // (12,18): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnPropertyGetter.Property = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(12, 18), + // (13,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertyGetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnPropertyGetter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(13, 5), + // (13,22): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnPropertyGetter.Property; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(13, 22), + // (14,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEvent").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(14, 1), + // (14,9): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(14, 9), + // (15,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEvent").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(15, 1), + // (15,9): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEvent.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(15, 9), + // (16,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventAdder").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(16, 1), + // (16,14): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(16, 14), + // (17,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventAdder").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(17, 1), + // (17,14): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventAdder.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(17, 14), + // (18,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventRemover").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(18, 1), + // (18,16): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event += () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(18, 16), + // (19,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEventRemover").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(19, 1), + // (19,16): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEventRemover.Event -= () => {}; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "Event").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(19, 16), + // (20,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnEnum onEnum; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEnum").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(20, 1), + // (21,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnEnumMember.A; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnEnumMember").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(21, 5), + // (21,18): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnEnumMember.A; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "A").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(21, 18), + // (22,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnClassTypeParameter onClassTypeParameter; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnClassTypeParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(22, 1), + // (23,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodTypeParameter.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnMethodTypeParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(23, 1), + // (23,23): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnMethodTypeParameter.M(); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "M").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(23, 23), + // (24,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnDelegateType onDelegateType; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnDelegateType").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(24, 1), + // (25,1): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnIndexedPropertyParameter.set_Property(1, 1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnIndexedPropertyParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(25, 1), + // (25,28): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // OnIndexedPropertyParameter.set_Property(1, 1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "set_Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(25, 28), + // (26,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnIndexedPropertyParameter.get_Property(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnIndexedPropertyParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(26, 5), + // (26,32): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = OnIndexedPropertyParameter.get_Property(1); + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "get_Property").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(26, 32), + // (27,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // new OnThisIndexerParameter()[1] = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(27, 5), + // (27,5): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // new OnThisIndexerParameter()[1] = 1; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(27, 5), + // (28,9): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = new OnThisIndexerParameter()[1]; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(28, 9), + // (28,9): error CS9512: 'AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' requires compiler feature 'test', which is not supported by this version of the C# compiler. + // _ = new OnThisIndexerParameter()[1]; + Diagnostic(ErrorCode.ERR_UnsupportedCompilerFeature, "OnThisIndexerParameter").WithArguments("AssemblyTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", "test").WithLocation(28, 9) + ); + + Assert.True(comp.GetReferencedAssemblySymbol(ilRef).HasUnsupportedMetadata); + } + + [Fact] + public void Application() + { + var comp = CSharpTestBase.CreateCompilation(new[] { """ + using System; + using System.Runtime.CompilerServices; + + [CompilerFeatureRequired("OnType")] + public class OnType + { + } + + public class OnMethod + { + [CompilerFeatureRequired("OnMethod")] + public static void M() {} + } + + public class OnMethodReturn + { + [return: CompilerFeatureRequired("OnMethodReturn")] + public static void M() {} + } + + public class OnParameter + { + public static void M([CompilerFeatureRequired("OnParameter")] int param) {} + } + + public class OnField + { + [CompilerFeatureRequired("OnField")] + public static int Field; + } + + public class OnProperty + { + [CompilerFeatureRequired("OnProperty")] + public static int Property { get => 0; set {} } + } + + public class OnPropertySetter + { + public static int Property { get => 0; [CompilerFeatureRequired("OnPropertySetter")] set {} } + } + + public class OnPropertyGetter + { + public static int Property { [CompilerFeatureRequired("OnPropertyGetter")] get => 0; set {} } + } + + public class OnEvent + { + [CompilerFeatureRequired("OnEvent")] + public static event Action Event { add {} remove {} } + } + + public class OnEventAdder + { + public static event Action Event { [CompilerFeatureRequired("OnEventAdder")] add {} remove {} } + } + + public class OnEventRemover + { + public static event Action Event { [CompilerFeatureRequired("OnEventRemover")] add {} remove {} } + } + + [CompilerFeatureRequired("OnEnum")] + public enum OnEnum + { + A + } + + public enum OnEnumMember + { + [CompilerFeatureRequired("OnEnumMember")] A + } + + public class OnClassTypeParameter<[CompilerFeatureRequired("OnClassTypeParameter")] T> + { + } + + public class OnMethodTypeParameter + { + public static void M<[CompilerFeatureRequired("OnMethodTypeParameter")] T>() {} + } + + [CompilerFeatureRequired("OnDelegateType")] + public delegate void OnDelegateType(); + """, CSharpTestBase.CompilerFeatureRequiredAttribute }); + + comp.VerifyDiagnostics( + // (4,2): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnType")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnType"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(4, 2), + // (11,6): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnMethod")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnMethod"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(11, 6), + // (17,14): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [return: CompilerFeatureRequired("OnMethodReturn")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnMethodReturn"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(17, 14), + // (23,27): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public static void M([CompilerFeatureRequired("OnParameter")] int param) {} + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnParameter"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(23, 27), + // (28,6): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnField")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnField"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(28, 6), + // (34,6): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnProperty")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnProperty"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(34, 6), + // (40,45): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public static int Property { get => 0; [CompilerFeatureRequired("OnPropertySetter")] set {} } + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnPropertySetter"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(40, 45), + // (45,35): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public static int Property { [CompilerFeatureRequired("OnPropertyGetter")] get => 0; set {} } + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnPropertyGetter"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(45, 35), + // (50,6): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnEvent")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnEvent"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(50, 6), + // (56,41): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public static event Action Event { [CompilerFeatureRequired("OnEventAdder")] add {} remove {} } + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnEventAdder"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(56, 41), + // (61,41): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public static event Action Event { [CompilerFeatureRequired("OnEventRemover")] add {} remove {} } + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnEventRemover"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(61, 41), + // (64,2): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnEnum")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnEnum"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(64, 2), + // (72,6): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnEnumMember")] A + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnEnumMember"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(72, 6), + // (75,36): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public class OnClassTypeParameter<[CompilerFeatureRequired("OnClassTypeParameter")] T> + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnClassTypeParameter"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(75, 36), + // (81,27): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // public static void M<[CompilerFeatureRequired("OnMethodTypeParameter")] T>() {} + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnMethodTypeParameter"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(81, 27), + // (84,2): error CS8335: Do not use 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute'. This is reserved for compiler usage. + // [CompilerFeatureRequired("OnDelegateType")] + Diagnostic(ErrorCode.ERR_ExplicitReservedAttr, @"CompilerFeatureRequired(""OnDelegateType"")").WithArguments("System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute").WithLocation(84, 2) + ); + } +} diff --git a/src/Compilers/Core/Portable/MetadataReader/PEModule.cs b/src/Compilers/Core/Portable/MetadataReader/PEModule.cs index cd0972fa881c7..16c3a5db53233 100644 --- a/src/Compilers/Core/Portable/MetadataReader/PEModule.cs +++ b/src/Compilers/Core/Portable/MetadataReader/PEModule.cs @@ -1149,6 +1149,60 @@ internal ObsoleteAttributeData TryGetDeprecatedOrExperimentalOrObsoleteAttribute } #nullable enable + internal string? GetFirstUnsupportedCompilerFeatureFromToken(EntityHandle token, IAttributeNamedArgumentDecoder attributeNamedArgumentDecoder, CompilerFeatureRequiredFeatures allowedFeatures) + { + List? infos = FindTargetAttributes(token, AttributeDescription.CompilerFeatureRequiredAttribute); + + if (infos == null) + { + return null; + } + + foreach (var info in infos) + { + if (!info.HasValue || !TryGetAttributeReader(info.Handle, out BlobReader sigReader) || !CrackStringInAttributeValue(out string? featureName, ref sigReader)) + { + continue; + } + + bool isOptional = false; + if (sigReader.RemainingBytes >= 2) + { + try + { + var numNamedArgs = sigReader.ReadUInt16(); + for (uint i = 0; i < numNamedArgs; i++) + { + (KeyValuePair nameValuePair, bool isProperty, SerializationTypeCode typeCode, SerializationTypeCode elementTypeCode) namedArgValues = + attributeNamedArgumentDecoder.DecodeCustomAttributeNamedArgumentOrThrow(ref sigReader); + + if (namedArgValues is ({ Key: "IsOptional" }, isProperty: true, typeCode: SerializationTypeCode.Boolean, _)) + { + isOptional = (bool)namedArgValues.nameValuePair.Value.ValueInternal!; + break; + } + } + } + catch (Exception e) when (e is UnsupportedSignatureContent or BadImageFormatException) { } + } + + if (!isOptional && (allowedFeatures & getFeatureKind(featureName)) == 0) + { + return featureName; + } + } + + return null; + + static CompilerFeatureRequiredFeatures getFeatureKind(string? feature) + => feature switch + { + nameof(CompilerFeatureRequiredFeatures.RefStructs) => CompilerFeatureRequiredFeatures.RefStructs, + nameof(CompilerFeatureRequiredFeatures.RequiredMembers) => CompilerFeatureRequiredFeatures.RequiredMembers, + _ => CompilerFeatureRequiredFeatures.None, + }; + } + internal UnmanagedCallersOnlyAttributeData? TryGetUnmanagedCallersOnlyAttribute( EntityHandle token, IAttributeNamedArgumentDecoder attributeArgumentDecoder, @@ -2133,9 +2187,10 @@ public bool HasValue } } - internal List FindTargetAttributes(EntityHandle hasAttribute, AttributeDescription description) +#nullable enable + internal List? FindTargetAttributes(EntityHandle hasAttribute, AttributeDescription description) { - List result = null; + List? result = null; try { @@ -2159,6 +2214,7 @@ internal List FindTargetAttributes(EntityHandle hasAttribute, Att return result; } +#nullable disable internal AttributeInfo FindTargetAttribute(EntityHandle hasAttribute, AttributeDescription description) { diff --git a/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs b/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs index 53a72b0bbd241..75575454f1da8 100644 --- a/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs +++ b/src/Compilers/Core/Portable/Symbols/Attributes/AttributeDescription.cs @@ -481,5 +481,6 @@ static AttributeDescription() internal static readonly AttributeDescription InterpolatedStringHandlerArgumentAttribute = new AttributeDescription("System.Runtime.CompilerServices", "InterpolatedStringHandlerArgumentAttribute", s_signaturesOfInterpolatedStringArgumentAttribute); internal static readonly AttributeDescription RequiredMemberAttribute = new AttributeDescription("System.Runtime.CompilerServices", "RequiredMemberAttribute", s_signatures_HasThis_Void_Only); internal static readonly AttributeDescription SetsRequiredMembersAttribute = new AttributeDescription("System.Diagnostics.CodeAnalysis", "SetsRequiredMembersAttribute", s_signatures_HasThis_Void_Only); + internal static readonly AttributeDescription CompilerFeatureRequiredAttribute = new AttributeDescription("System.Runtime.CompilerServices", "CompilerFeatureRequiredAttribute", s_signatures_HasThis_Void_String_Only); } } diff --git a/src/Compilers/Core/Portable/Symbols/CompilerFeatureRequiredFeatures.cs b/src/Compilers/Core/Portable/Symbols/CompilerFeatureRequiredFeatures.cs new file mode 100644 index 0000000000000..e4dc65b31dbf4 --- /dev/null +++ b/src/Compilers/Core/Portable/Symbols/CompilerFeatureRequiredFeatures.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; + +namespace Microsoft.CodeAnalysis; + +[Flags] +internal enum CompilerFeatureRequiredFeatures +{ + None = 0, + RefStructs = 1 << 0, + RequiredMembers = 1 << 1, +} diff --git a/src/Compilers/Test/Core/BaseCompilerFeatureRequiredTests.cs b/src/Compilers/Test/Core/BaseCompilerFeatureRequiredTests.cs new file mode 100644 index 0000000000000..4f12333daa6d0 --- /dev/null +++ b/src/Compilers/Test/Core/BaseCompilerFeatureRequiredTests.cs @@ -0,0 +1,710 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Linq; +using System.Reflection.Metadata; +using Microsoft.CodeAnalysis.Test.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.UnitTests; + +public abstract class BaseCompilerFeatureRequiredTests : CommonTestBase where TCompilation : Compilation +{ + private static string CompilerFeatureRequiredApplication( + bool? isOptional) + { + var builder = new BlobBuilder(); + builder.WriteSerializedString("test"); + var featureLengthAndName = string.Join(" ", builder.ToImmutableArray().Select(b => $"{b:x2}")); + + var isOptionalText = isOptional switch + { + true => "01 00 54 02 0a 49 73 4f 70 74 69 6f 6e 61 6c 01", // One optional parameter, "IsOptional", true + false => "01 00 54 02 0a 49 73 4f 70 74 69 6f 6e 61 6c 00", // One optional parameter, "IsOptional", false + null => "00 00" // No optional parameters + }; + + return $""" + .custom instance void System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::.ctor(string) = ( + 01 00 {featureLengthAndName} {isOptionalText} + ) + """; + } + + private const string CompilerFeatureRequiredIl = + """ + .class public auto ansi sealed beforefieldinit System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute + extends [mscorlib]System.Attribute + { + .custom instance void [mscorlib]System.AttributeUsageAttribute::.ctor(valuetype [mscorlib]System.AttributeTargets) = ( + 01 00 ff 7f 00 00 02 00 54 02 0d 41 6c 6c 6f 77 + 4d 75 6c 74 69 70 6c 65 01 54 02 09 49 6e 68 65 + 72 69 74 65 64 00 + ) + // Fields + .field private initonly string 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + .field private initonly bool 'k__BackingField' + .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( + 01 00 00 00 + ) + + .field public static literal string RefStructs = "RefStructs" + .field public static literal string RequiredMembers = "RequiredMembers" + + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor ( + string featureName + ) cil managed + { + ldarg.0 + call instance void [mscorlib]System.Attribute::.ctor() + ldarg.0 + ldarg.1 + stfld string System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::'k__BackingField' + ret + } // end of method CompilerFeatureRequiredAttribute::.ctor + + .method public hidebysig specialname + instance string get_FeatureName () cil managed + { + ldarg.0 + ldfld string System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::'k__BackingField' + ret + } // end of method CompilerFeatureRequiredAttribute::get_FeatureName + + .method public hidebysig specialname + instance bool get_IsOptional () cil managed + { + ldarg.0 + ldfld bool System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::'k__BackingField' + ret + } // end of method CompilerFeatureRequiredAttribute::get_IsOptional + + .method public hidebysig specialname + instance void modreq([mscorlib]System.Runtime.CompilerServices.IsExternalInit) set_IsOptional ( + bool 'value' + ) cil managed + { + ldarg.0 + ldarg.1 + stfld bool System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::'k__BackingField' + ret + } // end of method CompilerFeatureRequiredAttribute::set_IsOptional + + // Properties + .property instance string FeatureName() + { + .get instance string System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::get_FeatureName() + } + .property instance bool IsOptional() + { + .get instance bool System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::get_IsOptional() + .set instance void modreq([mscorlib]System.Runtime.CompilerServices.IsExternalInit) System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute::set_IsOptional(bool) + } + + } // end of class System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute + """; + + // This IL is equivalent to the following definition, which format holes for the required attribute under test: + // [CompilerFeatureRequired("test")] + // public class OnType + // { + // } + // + // public class OnMethod + // { + // [CompilerFeatureRequired("test")] + // public static void M() {} + // } + // + // public class OnMethodReturn + // { + // [return: CompilerFeatureRequired("test")] + // public static void M() {} + // } + // + // public class OnParameter + // { + // public static void M([CompilerFeatureRequired("test")] int param) {} + // } + // + // public class OnField + // { + // [CompilerFeatureRequired("test")] + // public static int Field; + // } + // + // public class OnProperty + // { + // [CompilerFeatureRequired("test")] + // public static int Property { get => 0; set {} } + // } + // + // public class OnPropertySetter + // { + // public static int Property { get => 0; [CompilerFeatureRequired("test")] set {} } + // } + // + // public class OnPropertyGetter + // { + // public static int Property { [CompilerFeatureRequired("test")] get => 0; set {} } + // } + // + // public class OnEvent + // { + // [CompilerFeatureRequired("test")] + // public static event Action Event { add {} remove {} } + // } + // + // public class OnEventAdder + // { + // public static event Action Event { [CompilerFeatureRequired("test")] add {} remove {} } + // } + // + // public class OnEventRemover + // { + // public static event Action Event { [CompilerFeatureRequired("test")] add {} remove {} } + // } + // + // [CompilerFeatureRequired("test")] + // public enum OnEnum + // { + // A + // } + // + // public enum OnEnumMember + // { + // [CompilerFeatureRequired("test")] A + // } + // + // public class OnClassTypeParameter<[CompilerFeatureRequired("test")] T> + // { + // } + // + // public class OnMethodTypeParameter + // { + // public static void M<[CompilerFeatureRequired("test")] T>() {} + // } + // + // [CompilerFeatureRequired("test")] + // public delegate void OnDelegateType(); + // + // VB: + // Public Class OnIndexedPropertyParameter + // Public Property [Property]( param As Integer) As Integer + // Get + // Return 1 + // End Get + // Set + // End Set + // End Property + // End Class + private string GetTestIl(string attributeApplication) + { + return $$""" + .class public auto ansi beforefieldinit OnType + extends [mscorlib]System.Object + { + {{attributeApplication}} + // Methods + .method public hidebysig static + void M () cil managed + { + ret + } // end of method OnMethod::M + } // end of class OnType + + .class public auto ansi beforefieldinit OnMethod + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig static + void M () cil managed + { + {{attributeApplication}} + ret + } // end of method OnMethod::M + } // end of class OnMethod + + .class public auto ansi beforefieldinit OnMethodReturn + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig static + void M () cil managed + { + .param [0] + {{attributeApplication}} + ret + } // end of method OnMethodReturn::M + } // end of class OnMethodReturn + + .class public auto ansi beforefieldinit OnParameter + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig static + void M ( + int32 param + ) cil managed + { + .param [1] + {{attributeApplication}} + ret + } // end of method OnParameter::M + } // end of class OnParameter + + .class public auto ansi beforefieldinit OnField + extends [mscorlib]System.Object + { + // Fields + .field public static int32 Field + {{attributeApplication}} + } // end of class OnField + + .class public auto ansi beforefieldinit OnProperty + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig specialname static + int32 get_Property () cil managed + { + ldc.i4.0 + ret + } // end of method OnProperty::get_Property + + .method public hidebysig specialname static + void set_Property ( + int32 'value' + ) cil managed + { + ret + } // end of method OnProperty::set_Property + + // Properties + .property int32 Property() + { + {{attributeApplication}} + .get int32 OnProperty::get_Property() + .set void OnProperty::set_Property(int32) + } + + } // end of class OnProperty + + .class public auto ansi beforefieldinit OnPropertySetter + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig specialname static + int32 get_Property () cil managed + { + ldc.i4.0 + ret + } // end of method OnPropertySetter::get_Property + + .method public hidebysig specialname static + void set_Property ( + int32 'value' + ) cil managed + { + {{attributeApplication}} + ret + } // end of method OnPropertySetter::set_Property + + // Properties + .property int32 Property() + { + .get int32 OnPropertySetter::get_Property() + .set void OnPropertySetter::set_Property(int32) + } + } // end of class OnPropertySetter + + .class public auto ansi beforefieldinit OnPropertyGetter + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig specialname static + int32 get_Property () cil managed + { + {{attributeApplication}} + ldc.i4.0 + ret + } // end of method OnPropertyGetter::get_Property + + .method public hidebysig specialname static + void set_Property ( + int32 'value' + ) cil managed + { + ret + } // end of method OnPropertyGetter::set_Property + + // Properties + .property int32 Property() + { + .get int32 OnPropertyGetter::get_Property() + .set void OnPropertyGetter::set_Property(int32) + } + + } // end of class OnPropertyGetter + + .class public auto ansi beforefieldinit OnEvent + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig specialname static + void add_Event ( + class [mscorlib]System.Action 'value' + ) cil managed + { + ret + } // end of method OnEvent::add_Event + + .method public hidebysig specialname static + void remove_Event ( + class [mscorlib]System.Action 'value' + ) cil managed + { + ret + } // end of method OnEvent::remove_Event + + // Events + .event [mscorlib]System.Action Event + { + {{attributeApplication}} + .addon void OnEvent::add_Event(class [mscorlib]System.Action) + .removeon void OnEvent::remove_Event(class [mscorlib]System.Action) + } + + + } // end of class OnEvent + + .class public auto ansi beforefieldinit OnEventAdder + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig specialname static + void add_Event ( + class [mscorlib]System.Action 'value' + ) cil managed + { + {{attributeApplication}} + ret + } // end of method OnEventAdder::add_Event + + .method public hidebysig specialname static + void remove_Event ( + class [mscorlib]System.Action 'value' + ) cil managed + { + ret + } // end of method OnEventAdder::remove_Event + + // Events + .event [mscorlib]System.Action Event + { + .addon void OnEventAdder::add_Event(class [mscorlib]System.Action) + .removeon void OnEventAdder::remove_Event(class [mscorlib]System.Action) + } + + + } // end of class OnEventAdder + + .class public auto ansi beforefieldinit OnEventRemover + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig specialname static + void add_Event ( + class [mscorlib]System.Action 'value' + ) cil managed + { + ret + } // end of method OnEventRemover::add_Event + + .method public hidebysig specialname static + void remove_Event ( + class [mscorlib]System.Action 'value' + ) cil managed + { + {{attributeApplication}} + ret + } // end of method OnEventRemover::remove_Event + + // Events + .event [mscorlib]System.Action Event + { + .addon void OnEventRemover::add_Event(class [mscorlib]System.Action) + .removeon void OnEventRemover::remove_Event(class [mscorlib]System.Action) + } + + + } // end of class OnEventRemover + + .class public auto ansi sealed OnEnum + extends [mscorlib]System.Enum + { + {{attributeApplication}} + // Fields + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype OnEnum A = int32(0) + + } // end of class OnEnum + + .class public auto ansi sealed OnEnumMember + extends [mscorlib]System.Enum + { + // Fields + .field public specialname rtspecialname int32 value__ + .field public static literal valuetype OnEnumMember A = int32(0) + {{attributeApplication}} + + } // end of class OnEnumMember + + .class public auto ansi beforefieldinit OnClassTypeParameter`1 + extends [mscorlib]System.Object + { + .param type T + {{attributeApplication}} + } // end of class OnClassTypeParameter`1 + + .class public auto ansi beforefieldinit OnMethodTypeParameter + extends [mscorlib]System.Object + { + // Methods + .method public hidebysig static + void M () cil managed + { + .param type T + {{attributeApplication}} + ret + } // end of method OnMethodTypeParameter::M + } // end of class OnMethodTypeParameter + + .class public auto ansi sealed OnDelegateType + extends [mscorlib]System.MulticastDelegate + { + {{attributeApplication}} + // Methods + .method public hidebysig specialname rtspecialname + instance void .ctor ( + object 'object', + native int 'method' + ) runtime managed + { + } // end of method OnDelegateType::.ctor + + .method public hidebysig newslot virtual + instance void Invoke () runtime managed + { + } // end of method OnDelegateType::Invoke + + .method public hidebysig newslot virtual + instance class [mscorlib]System.IAsyncResult BeginInvoke ( + class [mscorlib]System.AsyncCallback callback, + object 'object' + ) runtime managed + { + } // end of method OnDelegateType::BeginInvoke + + .method public hidebysig newslot virtual + instance void EndInvoke ( + class [mscorlib]System.IAsyncResult result + ) runtime managed + { + } // end of method OnDelegateType::EndInvoke + + } // end of class OnDelegateType + + .class public auto ansi OnIndexedPropertyParameter + extends [mscorlib]System.Object + { + // Methods + .method public specialname static + int32 get_Property ( + int32 param + ) cil managed + { + .param [1] + {{attributeApplication}} + + ldc.i4.1 + stloc.0 + ldloc.0 + ret + } // end of method OnIndexedPropertyParameter::get_Property + + .method public specialname static + void set_Property ( + int32 param, + int32 Value + ) cil managed + { + .param [1] + {{attributeApplication}} + + ret + } // end of method OnIndexedPropertyParameter::set_Property + + // Properties + .property int32 Property( + int32 param + ) + { + .get int32 OnIndexedPropertyParameter::get_Property(int32) + .set void OnIndexedPropertyParameter::set_Property(int32, int32) + } + + } // end of class OnIndexedPropertyParameter + + .class public auto ansi beforefieldinit OnThisIndexerParameter + extends [mscorlib]System.Object + { + .custom instance void [mscorlib]System.Reflection.DefaultMemberAttribute::.ctor(string) = ( + 01 00 04 49 74 65 6d 00 00 + ) + // Methods + .method public hidebysig specialname + instance int32 get_Item ( + int32 i + ) cil managed + { + .param [1] + {{attributeApplication}} + ldc.i4.0 + ret + } // end of method OnThisIndexerParameter::get_Item + + .method public hidebysig specialname + instance void set_Item ( + int32 i, + int32 'value' + ) cil managed + { + .param [1] + {{attributeApplication}} + ret + } // end of method OnThisIndexerParameter::set_Item + + .method public hidebysig specialname rtspecialname + instance void .ctor () cil managed + { + ldarg.0 + call instance void [mscorlib]System.Object::.ctor() + ret + } // end of method OnThisIndexerParameter::.ctor + + // Properties + .property instance int32 Item( + int32 i + ) + { + .get instance int32 OnThisIndexerParameter::get_Item(int32) + .set instance void OnThisIndexerParameter::set_Item(int32, int32) + } + } // end of class OnThisIndexerParameter + """; + } + + protected abstract TSource GetUsage(); + protected abstract TCompilation CreateCompilationWithIL(TSource source, string ilSource); + protected abstract TCompilation CreateCompilation(TSource source, MetadataReference[] references); + protected abstract CompilationVerifier CompileAndVerify(TCompilation compilation); + + [Theory] + [InlineData(true)] + [InlineData(false)] + [InlineData(null)] + public void OnNormalSymbols(bool? isOptional) + { + var testIl = $""" + {CompilerFeatureRequiredIl} + {GetTestIl(CompilerFeatureRequiredApplication(isOptional: isOptional))} + """; + var comp = CreateCompilationWithIL(source: GetUsage(), ilSource: testIl); + + if (isOptional == true) + { + CompileAndVerify(comp).VerifyDiagnostics(); + } + else + { + AssertNormalErrors(comp); + } + } + + protected abstract void AssertNormalErrors(TCompilation compilation); + + [Theory] + [InlineData(true)] + [InlineData(false)] + [InlineData(null)] + public void OnAssembly(bool? isOptional) + { + var il = $$""" + .assembly 'AssemblyTest' + { + {{CompilerFeatureRequiredApplication(isOptional: isOptional)}} + } + + .assembly extern mscorlib + { + .publickeytoken = (B7 7A 5C 56 19 34 E0 89) + .ver 4:0:0:0 + } + + {{CompilerFeatureRequiredIl}} + {{GetTestIl(attributeApplication: "")}} + """; + + var compiledIl = CompileIL(il, prependDefaultHeader: false); + + var comp = CreateCompilation(source: GetUsage(), references: new[] { compiledIl }); + + if (isOptional == true) + { + CompileAndVerify(comp).VerifyDiagnostics(); + } + else + { + AssertAssemblyErrors(comp, compiledIl); + } + } + + protected abstract void AssertAssemblyErrors(TCompilation compilation, MetadataReference ilRef); + + [Theory] + [InlineData(true)] + [InlineData(false)] + [InlineData(null)] + public void OnModule(bool? isOptional) + { + var il = $$""" + .module OnModule + {{CompilerFeatureRequiredApplication(isOptional: isOptional)}} + + {{CompilerFeatureRequiredIl}} + {{GetTestIl(attributeApplication: "")}} + """; + + + var compiledIl = CompileIL(il); + var comp = CreateCompilation(source: GetUsage(), references: new[] { compiledIl }); + + if (isOptional == true) + { + CompileAndVerify(comp).VerifyDiagnostics(); + } + else + { + AssertModuleErrors(comp, compiledIl); + } + } + + protected abstract void AssertModuleErrors(TCompilation compilation, MetadataReference ilRef); +} diff --git a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs index 9b9c1c9200af6..21a72e50b5527 100644 --- a/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs +++ b/src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs @@ -651,6 +651,22 @@ public SetsRequiredMembersAttribute() } "; + internal const string CompilerFeatureRequiredAttribute = """ + namespace System.Runtime.CompilerServices + { + [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)] + public sealed class CompilerFeatureRequiredAttribute : Attribute + { + public CompilerFeatureRequiredAttribute(string featureName) + { + FeatureName = featureName; + } + public string FeatureName { get; } + public bool IsOptional { get; set; } + } + } + """; + protected static CSharpCompilationOptions WithNullableEnable(CSharpCompilationOptions options = null) { return WithNullable(options, NullableContextOptions.Enable); diff --git a/src/Compilers/VisualBasic/Portable/Binding/Binder.vb b/src/Compilers/VisualBasic/Portable/Binding/Binder.vb index 60e4e3a773b20..c5c56102eff92 100644 --- a/src/Compilers/VisualBasic/Portable/Binding/Binder.vb +++ b/src/Compilers/VisualBasic/Portable/Binding/Binder.vb @@ -575,7 +575,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = member.GetUseSiteInfo() If useSiteInfo.DiagnosticInfo Is Nothing Then - Symbol.MergeUseSiteInfo(useSiteInfo, member.ContainingType.GetUseSiteInfo(), highestPriorityUseSiteError:=0) + member.MergeUseSiteInfo(useSiteInfo, member.ContainingType.GetUseSiteInfo()) End If Return useSiteInfo diff --git a/src/Compilers/VisualBasic/Portable/Errors/ErrorFactories.vb b/src/Compilers/VisualBasic/Portable/Errors/ErrorFactories.vb index 71b099a93abdf..023c7c2731778 100644 --- a/src/Compilers/VisualBasic/Portable/Errors/ErrorFactories.vb +++ b/src/Compilers/VisualBasic/Portable/Errors/ErrorFactories.vb @@ -26,6 +26,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Function Public Shared ReadOnly VoidDiagnosticInfo As DiagnosticInfo = ErrorInfo(ERRID.Void) + Public Shared ReadOnly EmptyDiagnosticInfo As DiagnosticInfo = ErrorInfo(ERRID.ERR_None) Public Shared ReadOnly GetErrorInfo_ERR_WithEventsRequiresClass As Func(Of DiagnosticInfo) = Function() ErrorInfo(ERRID.ERR_WithEventsRequiresClass) diff --git a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb index 9cd4e9a6c63c4..dc5213173ded5 100644 --- a/src/Compilers/VisualBasic/Portable/Errors/Errors.vb +++ b/src/Compilers/VisualBasic/Portable/Errors/Errors.vb @@ -1764,7 +1764,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ERR_MultipleAnalyzerConfigsInSameDir = 37317 ERR_StdInOptionProvidedButConsoleInputIsNotRedirected = 37318 - ERR_NextAvailable = 37319 + ERR_UnsupportedCompilerFeature = 37319 + ERR_DoNotUseCompilerFeatureRequired = 37320 + + ERR_NextAvailable = 37321 '// WARNINGS BEGIN HERE WRN_UseOfObsoleteSymbol2 = 40000 diff --git a/src/Compilers/VisualBasic/Portable/Symbols/ArrayTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/ArrayTypeSymbol.vb index fe5c553eaf68a..cb522160892b6 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/ArrayTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/ArrayTypeSymbol.vb @@ -369,14 +369,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Check type. Dim elementUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromType(Me.ElementType) - If elementUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedType1 Then + If elementUseSiteInfo.DiagnosticInfo IsNot Nothing AndAlso IsHighestPriorityUseSiteError(elementUseSiteInfo.DiagnosticInfo.Code) Then Return elementUseSiteInfo End If ' Check custom modifiers. Dim modifiersUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromCustomModifiers(Me.CustomModifiers) - Return MergeUseSiteInfo(elementUseSiteInfo, modifiersUseSiteInfo) + MergeUseSiteInfo(elementUseSiteInfo, modifiersUseSiteInfo) + Return elementUseSiteInfo End Function Friend Overrides Function GetUnificationUseSiteDiagnosticRecursive(owner As Symbol, ByRef checkedTypes As HashSet(Of TypeSymbol)) As DiagnosticInfo diff --git a/src/Compilers/VisualBasic/Portable/Symbols/EventSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/EventSymbol.vb index 70241f7359c4b..3a033ba0e0afc 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/EventSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/EventSymbol.vb @@ -195,7 +195,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Friend Function CalculateUseSiteInfo() As UseSiteInfo(Of AssemblySymbol) Debug.Assert(Me.IsDefinition) ' Check event type. - Dim useSiteInfo = MergeUseSiteInfo(New UseSiteInfo(Of AssemblySymbol)(PrimaryDependency), DeriveUseSiteInfoFromType(Me.Type)) + Dim useSiteInfo = New UseSiteInfo(Of AssemblySymbol)(PrimaryDependency) + MergeUseSiteInfo(useSiteInfo, DeriveUseSiteInfoFromType(Me.Type)) Dim errorInfo As DiagnosticInfo = useSiteInfo.DiagnosticInfo If errorInfo IsNot Nothing Then @@ -237,16 +238,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Return useSiteInfo End Function - Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer - Get - Return ERRID.ERR_UnsupportedType1 - End Get - End Property + Protected Overrides Function IsHighestPriorityUseSiteError(code As Integer) As Boolean + Return code = ERRID.ERR_UnsupportedType1 OrElse code = ERRID.ERR_UnsupportedCompilerFeature + End Function Public NotOverridable Overrides ReadOnly Property HasUnsupportedMetadata As Boolean Get Dim info As DiagnosticInfo = GetUseSiteInfo().DiagnosticInfo - Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedType1 OrElse info.Code = ERRID.ERR_UnsupportedEvent1) + Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedType1 OrElse info.Code = ERRID.ERR_UnsupportedEvent1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature) End Get End Property diff --git a/src/Compilers/VisualBasic/Portable/Symbols/FieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/FieldSymbol.vb index 88924bd0e60d8..0b78e80d1a746 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/FieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/FieldSymbol.vb @@ -280,21 +280,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Debug.Assert(IsDefinition) ' Check type. - Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = MergeUseSiteInfo(New UseSiteInfo(Of AssemblySymbol)(PrimaryDependency), DeriveUseSiteInfoFromType(Me.Type)) + Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = New UseSiteInfo(Of AssemblySymbol)(PrimaryDependency) - If useSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedField1 Then + If MergeUseSiteInfo(useSiteInfo, DeriveUseSiteInfoFromType(Me.Type)) Then Return useSiteInfo End If ' Check custom modifiers. Dim modifiersUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromCustomModifiers(Me.CustomModifiers) - If modifiersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedField1 Then - Return modifiersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, modifiersUseSiteInfo) Then + Return useSiteInfo End If - useSiteInfo = MergeUseSiteInfo(useSiteInfo, modifiersUseSiteInfo) - ' If the member is in an assembly with unified references, ' we check if its definition depends on a type from a unified reference. If useSiteInfo.DiagnosticInfo Is Nothing AndAlso Me.ContainingModule.HasUnifiedReferences Then @@ -315,16 +313,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' ''' Return error code that has highest priority while calculating use site error for this symbol. ''' - Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer - Get - Return ERRID.ERR_UnsupportedField1 - End Get - End Property + Protected Overrides Function IsHighestPriorityUseSiteError(code As Integer) As Boolean + Return code = ERRID.ERR_UnsupportedField1 OrElse code = ERRID.ERR_UnsupportedCompilerFeature + End Function Public NotOverridable Overrides ReadOnly Property HasUnsupportedMetadata As Boolean Get Dim info As DiagnosticInfo = GetUseSiteInfo().DiagnosticInfo - Return info IsNot Nothing AndAlso info.Code = ERRID.ERR_UnsupportedField1 + Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedField1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature) End Get End Property diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEAssemblySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEAssemblySymbol.vb index 2cbea1d30b4e2..b7ac701c2213a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEAssemblySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEAssemblySymbol.vb @@ -11,6 +11,7 @@ Imports Microsoft.CodeAnalysis.VisualBasic.Symbols Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports System.Runtime.InteropServices Imports System.Reflection.Metadata.Ecma335 +Imports System.Threading Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE @@ -65,6 +66,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Private _lazyCustomAttributes As ImmutableArray(Of VisualBasicAttributeData) + Private _lazyCachedCompilerFeatureRequiredDiagnosticInfo As DiagnosticInfo = ErrorFactory.EmptyDiagnosticInfo + Friend Sub New(assembly As PEAssembly, documentationProvider As DocumentationProvider, isLinked As Boolean, importOptions As MetadataImportOptions) Debug.Assert(assembly IsNot Nothing) @@ -257,5 +260,27 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Public Overrides Function GetMetadata() As AssemblyMetadata Return _assembly.GetNonDisposableMetadata() End Function + + Friend Function GetCompilerFeatureRequiredDiagnosticInfo() As DiagnosticInfo + If _lazyCachedCompilerFeatureRequiredDiagnosticInfo Is ErrorFactory.EmptyDiagnosticInfo Then + Interlocked.CompareExchange( + _lazyCachedCompilerFeatureRequiredDiagnosticInfo, + DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, PrimaryModule, _assembly.Handle, CompilerFeatureRequiredFeatures.None, New MetadataDecoder(PrimaryModule)), + ErrorFactory.EmptyDiagnosticInfo) + End If + + Return _lazyCachedCompilerFeatureRequiredDiagnosticInfo + End Function + + Public Overrides ReadOnly Property HasUnsupportedMetadata As Boolean + Get + Dim info = GetCompilerFeatureRequiredDiagnosticInfo() + If info IsNot Nothing Then + Return info.Code = DirectCast(ERRID.ERR_UnsupportedCompilerFeature, Integer) OrElse MyBase.HasUnsupportedMetadata + End If + + Return MyBase.HasUnsupportedMetadata + End Get + End Property End Class End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEEventSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEEventSymbol.vb index 8b97e585a9c4d..d72f126a5fbcb 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEEventSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEEventSymbol.vb @@ -291,14 +291,38 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Friend Overrides Function GetUseSiteInfo() As UseSiteInfo(Of AssemblySymbol) Dim primaryDependency As AssemblySymbol = Me.PrimaryDependency + Dim containingModule = _containingType.ContainingPEModule If Not _lazyCachedUseSiteInfo.IsInitialized Then - _lazyCachedUseSiteInfo.Initialize(primaryDependency, CalculateUseSiteInfo()) + Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = CalculateUseSiteInfo() + Dim errorInfo = useSiteInfo.DiagnosticInfo + DeriveCompilerFeatureRequiredDiagnostic(errorInfo) + _lazyCachedUseSiteInfo.Initialize(primaryDependency, useSiteInfo.AdjustDiagnosticInfo(errorInfo)) End If Return _lazyCachedUseSiteInfo.ToUseSiteInfo(primaryDependency) End Function + Private Sub DeriveCompilerFeatureRequiredDiagnostic(ByRef errorInfo As DiagnosticInfo) + If errorInfo IsNot Nothing Then + Return + End If + + Dim containingModule = _containingType.ContainingPEModule + errorInfo = DeriveCompilerFeatureRequiredAttributeDiagnostic( + Me, + containingModule, + Handle, + CompilerFeatureRequiredFeatures.None, + New MetadataDecoder(containingModule, _containingType)) + + If errorInfo IsNot Nothing Then + Return + End If + + errorInfo = _containingType.GetCompilerFeatureRequiredDiagnostic() + End Sub + ''' ''' This is for perf, not for correctness. ''' diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb index bb09dc34f1427..159f2adc4e68e 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEFieldSymbol.vb @@ -383,6 +383,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE If Not _lazyCachedUseSiteInfo.IsInitialized Then Dim fieldUseSiteInfo = CalculateUseSiteInfo() + If fieldUseSiteInfo.DiagnosticInfo Is Nothing Then + Dim errorInfo = DeriveCompilerFeatureRequiredDiagnostic(fieldUseSiteInfo) + If errorInfo IsNot Nothing Then + fieldUseSiteInfo = New UseSiteInfo(Of AssemblySymbol)(errorInfo) + End If + End If + ' if there was no previous use site error for this symbol, check the constant value If fieldUseSiteInfo.DiagnosticInfo Is Nothing Then @@ -403,6 +410,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Return _lazyCachedUseSiteInfo.ToUseSiteInfo(primaryDependency) End Function + Private Function DeriveCompilerFeatureRequiredDiagnostic(ByRef result As UseSiteInfo(Of AssemblySymbol)) As DiagnosticInfo + Dim containingModule = _containingType.ContainingPEModule + Return If(DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, containingModule, Handle, CompilerFeatureRequiredFeatures.None, New MetadataDecoder(containingModule, _containingType)), + _containingType.GetCompilerFeatureRequiredDiagnostic()) + End Function + Friend ReadOnly Property Handle As FieldDefinitionHandle Get Return _handle diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb index 0258db8c72de9..6217c89a4675d 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEMethodSymbol.vb @@ -388,7 +388,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End If End If - If Not IsShared AndAlso String.Equals(name, WellKnownMemberNames.DelegateInvokeName, StringComparison.Ordinal) AndAlso _containingType.TypeKind = TYPEKIND.Delegate Then + If Not IsShared AndAlso String.Equals(name, WellKnownMemberNames.DelegateInvokeName, StringComparison.Ordinal) AndAlso _containingType.TypeKind = TypeKind.Delegate Then Return MethodKind.DelegateInvoke End If @@ -949,7 +949,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE ''' false if the method is already associated with a property or event. ''' Friend Function SetAssociatedProperty(propertySymbol As PEPropertySymbol, methodKind As MethodKind) As Boolean - Debug.Assert((methodKind = methodKind.PropertyGet) OrElse (methodKind = methodKind.PropertySet)) + Debug.Assert((methodKind = MethodKind.PropertyGet) OrElse (methodKind = MethodKind.PropertySet)) Return Me.SetAssociatedPropertyOrEvent(propertySymbol, methodKind) End Function @@ -958,7 +958,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE ''' false if the method is already associated with a property or event. ''' Friend Function SetAssociatedEvent(eventSymbol As PEEventSymbol, methodKind As MethodKind) As Boolean - Debug.Assert((methodKind = methodKind.EventAdd) OrElse (methodKind = methodKind.EventRemove) OrElse (methodKind = methodKind.EventRaise)) + Debug.Assert((methodKind = MethodKind.EventAdd) OrElse (methodKind = MethodKind.EventRemove) OrElse (methodKind = MethodKind.EventRaise)) Return Me.SetAssociatedPropertyOrEvent(eventSymbol, methodKind) End Function @@ -1143,6 +1143,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE If Not _packedFlags.IsUseSiteDiagnosticPopulated Then Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = CalculateUseSiteInfo() Dim errorInfo As DiagnosticInfo = useSiteInfo.DiagnosticInfo + DeriveCompilerFeatureRequiredUseSiteInfo(errorInfo) EnsureTypeParametersAreLoaded(errorInfo) CheckUnmanagedCallersOnly(errorInfo) Return InitializeUseSiteInfo(useSiteInfo.AdjustDiagnosticInfo(errorInfo)) @@ -1166,6 +1167,41 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End If End Sub + Private Sub DeriveCompilerFeatureRequiredUseSiteInfo(ByRef errorInfo As DiagnosticInfo) + If errorInfo IsNot Nothing Then + Return + End If + + Dim containingModule = _containingType.ContainingPEModule + Dim decoder As New MetadataDecoder(containingModule, Me) + + errorInfo = DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, DirectCast(containingModule, PEModuleSymbol), Handle, CompilerFeatureRequiredFeatures.None, decoder) + If errorInfo IsNot Nothing Then + Return + End If + + errorInfo = Signature.ReturnParam.DeriveCompilerFeatureRequiredDiagnostic(decoder) + If errorInfo IsNot Nothing Then + Return + End If + + For Each parameter In Parameters + errorInfo = DirectCast(parameter, PEParameterSymbol).DeriveCompilerFeatureRequiredDiagnostic(decoder) + If errorInfo IsNot Nothing Then + Return + End If + Next + + For Each typeParameter In TypeParameters + errorInfo = DirectCast(typeParameter, PETypeParameterSymbol).DeriveCompilerFeatureRequiredDiagnostic(decoder) + If errorInfo IsNot Nothing Then + Return + End If + Next + + errorInfo = _containingType.GetCompilerFeatureRequiredDiagnostic() + End Sub + Private Function InitializeUseSiteInfo(useSiteInfo As UseSiteInfo(Of AssemblySymbol)) As UseSiteInfo(Of AssemblySymbol) If _packedFlags.IsUseSiteDiagnosticPopulated Then Return GetCachedUseSiteInfo() diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEModuleSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEModuleSymbol.vb index 1eeb87e58d3bd..e3b80d4cd247a 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEModuleSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEModuleSymbol.vb @@ -79,6 +79,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Private _lazyTypeNames As ICollection(Of String) Private _lazyNamespaceNames As ICollection(Of String) + Private _lazyCachedCompilerFeatureRequiredDiagnosticInfo As DiagnosticInfo = ErrorFactory.EmptyDiagnosticInfo + Friend Sub New(assemblySymbol As PEAssemblySymbol, [module] As PEModule, importOptions As MetadataImportOptions, ordinal As Integer) Me.New(DirectCast(assemblySymbol, AssemblySymbol), [module], importOptions, ordinal) Debug.Assert(ordinal >= 0) @@ -466,7 +468,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Yield ContainingAssembly.CreateMultipleForwardingErrorTypeSymbol(name, Me, firstSymbol, secondSymbol) Else - Yield firstSymbol.LookupTopLevelMetadataType(name, digThroughForwardedTypes:=true) + Yield firstSymbol.LookupTopLevelMetadataType(name, digThroughForwardedTypes:=True) End If Next End Function @@ -484,5 +486,28 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Public Overrides Function GetMetadata() As ModuleMetadata Return _module.GetNonDisposableMetadata() End Function + + Friend Function GetCompilerFeatureRequiredDiagnostic() As DiagnosticInfo + If _lazyCachedCompilerFeatureRequiredDiagnosticInfo Is ErrorFactory.EmptyDiagnosticInfo Then + Interlocked.CompareExchange( + _lazyCachedCompilerFeatureRequiredDiagnosticInfo, + DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, Me, EntityHandle.ModuleDefinition, CompilerFeatureRequiredFeatures.None, New MetadataDecoder(Me)), + ErrorFactory.EmptyDiagnosticInfo) + End If + + Return If(_lazyCachedCompilerFeatureRequiredDiagnosticInfo, + TryCast(ContainingAssembly, PEAssemblySymbol)?.GetCompilerFeatureRequiredDiagnosticInfo()) + End Function + + Public Overrides ReadOnly Property HasUnsupportedMetadata As Boolean + Get + Dim info = GetCompilerFeatureRequiredDiagnostic() + If info IsNot Nothing Then + Return info.Code = DirectCast(ERRID.ERR_UnsupportedCompilerFeature, Integer) OrElse MyBase.HasUnsupportedMetadata + End If + + Return MyBase.HasUnsupportedMetadata + End Get + End Property End Class End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb index 26f53df3b08ee..66e1b5ce8715b 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PENamedTypeSymbol.vb @@ -164,7 +164,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End If If makeBad OrElse metadataArity < containerMetadataArity Then - _lazyCachedUseSiteInfo.Initialize(ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedType1, Me)) + _lazyCachedUseSiteInfo.Initialize(If(DeriveCompilerFeatureRequiredDiagnostic(), ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedType1, Me))) End If Debug.Assert(Not _mangleName OrElse _name.Length < name.Length) @@ -1274,6 +1274,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End Function Private Function CalculateUseSiteInfoImpl() As UseSiteInfo(Of AssemblySymbol) + ' GetCompilerFeatureRequiredDiagnostic depends on this being the highest priority use-site diagnostic. If another + ' diagnostic was calculated first and cached, it will return incorrect results and assert in Debug mode. + Dim compilerFeatureRequiredDiagnostic = DeriveCompilerFeatureRequiredDiagnostic() + If compilerFeatureRequiredDiagnostic IsNot Nothing Then + Return New UseSiteInfo(Of AssemblySymbol)(compilerFeatureRequiredDiagnostic) + End If + Dim useSiteInfo = CalculateUseSiteInfo() If useSiteInfo.DiagnosticInfo Is Nothing Then @@ -1318,6 +1325,39 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Return useSiteInfo End Function + Friend Function GetCompilerFeatureRequiredDiagnostic() As DiagnosticInfo + Dim typeUseSiteInfo = GetUseSiteInfo() + If typeUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedCompilerFeature Then + Return typeUseSiteInfo.DiagnosticInfo + End If + + Debug.Assert(DeriveCompilerFeatureRequiredDiagnostic() Is Nothing) + + Return Nothing + End Function + + Private Function DeriveCompilerFeatureRequiredDiagnostic() As DiagnosticInfo + Dim decoder = New MetadataDecoder(ContainingPEModule, Me) + + Dim diagnostic = DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, ContainingPEModule, Handle, CompilerFeatureRequiredFeatures.None, decoder) + + If diagnostic IsNot Nothing Then + Return diagnostic + End If + + For Each typeParameter In TypeParameters + diagnostic = DirectCast(typeParameter, PETypeParameterSymbol).DeriveCompilerFeatureRequiredDiagnostic(decoder) + + If diagnostic IsNot Nothing Then + Return diagnostic + End If + Next + + Dim containingPEType = TryCast(ContainingType, PENamedTypeSymbol) + + Return If(containingPEType IsNot Nothing, containingPEType.GetCompilerFeatureRequiredDiagnostic(), ContainingPEModule.GetCompilerFeatureRequiredDiagnostic()) + End Function + ''' ''' Return true if the type parameters specified on the nested type (Me), ''' that represent the corresponding type parameters on the containing diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb index 21b1018a09ebd..8865007dbdcb9 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEParameterSymbol.vb @@ -655,5 +655,23 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Return DirectCast(_containingSymbol.ContainingModule, PEModuleSymbol).Module End Get End Property + + Friend Function DeriveCompilerFeatureRequiredDiagnostic(decoder As MetadataDecoder) As DiagnosticInfo + Return DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, DirectCast(Me.ContainingModule, PEModuleSymbol), Handle, CompilerFeatureRequiredFeatures.None, decoder) + End Function + + Public Overrides ReadOnly Property HasUnsupportedMetadata As Boolean + Get + Dim containingModule = DirectCast(Me.ContainingModule, PEModuleSymbol) + Dim containingMethod = TryCast(Me.ContainingSymbol, PEMethodSymbol) + Dim decoder = If(containingMethod IsNot Nothing, + New MetadataDecoder(containingModule, containingMethod), + New MetadataDecoder(containingModule, DirectCast(ContainingType, PENamedTypeSymbol))) + + Dim info = DeriveCompilerFeatureRequiredDiagnostic(decoder) + + Return (info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedType1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature)) OrElse MyBase.HasUnsupportedMetadata + End Get + End Property End Class End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEPropertySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEPropertySymbol.vb index 7756a63151118..6a12ecc276166 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEPropertySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEPropertySymbol.vb @@ -545,12 +545,43 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Dim primaryDependency As AssemblySymbol = Me.PrimaryDependency If Not _lazyCachedUseSiteInfo.IsInitialized Then - _lazyCachedUseSiteInfo.Initialize(primaryDependency, CalculateUseSiteInfo()) + Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = CalculateUseSiteInfo() + Dim errorInfo = useSiteInfo.DiagnosticInfo + DeriveCompilerFeatureRequiredDiagnostic(errorInfo) + _lazyCachedUseSiteInfo.Initialize(primaryDependency, useSiteInfo.AdjustDiagnosticInfo(errorInfo)) End If Return _lazyCachedUseSiteInfo.ToUseSiteInfo(primaryDependency) End Function + Private Sub DeriveCompilerFeatureRequiredDiagnostic(ByRef errorInfo As DiagnosticInfo) + If errorInfo IsNot Nothing Then + Return + End If + + Dim containingModule = _containingType.ContainingPEModule + Dim decoder = New MetadataDecoder(containingModule, _containingType) + errorInfo = DeriveCompilerFeatureRequiredAttributeDiagnostic( + Me, + containingModule, + Handle, + CompilerFeatureRequiredFeatures.None, + decoder) + + If errorInfo IsNot Nothing Then + Return + End If + + For Each param In Parameters + errorInfo = DirectCast(param, PEParameterSymbol).DeriveCompilerFeatureRequiredDiagnostic(decoder) + If errorInfo IsNot Nothing Then + Return + End If + Next + + errorInfo = _containingType.GetCompilerFeatureRequiredDiagnostic() + End Sub + Friend ReadOnly Property Handle As PropertyDefinitionHandle Get Return _handle diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.vb index 175d97bab669a..1ecc93c7051df 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PETypeParameterSymbol.vb @@ -284,7 +284,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Dim useSiteInfo As New UseSiteInfo(Of AssemblySymbol)(primaryDependency) For Each pair In diagnosticsBuilder - useSiteInfo = MergeUseSiteInfo(useSiteInfo, pair.UseSiteInfo) + MergeUseSiteInfo(useSiteInfo, pair.UseSiteInfo) If useSiteInfo.DiagnosticInfo IsNot Nothing Then Exit For End If @@ -305,6 +305,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE Return _lazyCachedBoundsUseSiteInfo.ToUseSiteInfo(PrimaryDependency) End Function + Friend Function DeriveCompilerFeatureRequiredDiagnostic(decoder As MetadataDecoder) As DiagnosticInfo + Return DeriveCompilerFeatureRequiredAttributeDiagnostic(Me, DirectCast(ContainingModule, PEModuleSymbol), Handle, CompilerFeatureRequiredFeatures.None, decoder) + End Function + ''' ''' This is for perf, not for correctness. ''' @@ -314,6 +318,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE End Get End Property + Public Overrides ReadOnly Property HasUnsupportedMetadata As Boolean + Get + Dim containingModule = DirectCast(Me.ContainingModule, PEModuleSymbol) + Dim containingMethod = TryCast(Me.ContainingSymbol, PEMethodSymbol) + Dim decoder = If(containingMethod IsNot Nothing, + New MetadataDecoder(containingModule, containingMethod), + New MetadataDecoder(containingModule, DirectCast(ContainingSymbol, PENamedTypeSymbol))) + Dim info As DiagnosticInfo = DeriveCompilerFeatureRequiredDiagnostic(decoder) + + Return info IsNot Nothing AndAlso info.Code = DirectCast(ERRID.ERR_UnsupportedCompilerFeature, Integer) OrElse MyBase.HasUnsupportedMetadata + End Get + End Property + End Class End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEUtilities.vb b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEUtilities.vb new file mode 100644 index 0000000000000..aca8e9c580f3e --- /dev/null +++ b/src/Compilers/VisualBasic/Portable/Symbols/Metadata/PE/PEUtilities.vb @@ -0,0 +1,18 @@ +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE + Module PEUtilities + + Friend Function DeriveCompilerFeatureRequiredAttributeDiagnostic(symbol As Symbol, [module] As PEModuleSymbol, handle As System.Reflection.Metadata.EntityHandle, allowedFeatures As CompilerFeatureRequiredFeatures, decoder As MetadataDecoder) As DiagnosticInfo + Dim unsupportedFeature = [module].Module.GetFirstUnsupportedCompilerFeatureFromToken(handle, decoder, allowedFeatures) + If unsupportedFeature IsNot Nothing Then + ' '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + Return ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedCompilerFeature, symbol, unsupportedFeature) + Else + Return Nothing + End If + End Function + End Module +End Namespace diff --git a/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb index e0e2004668807..b4281e0f81983 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb @@ -633,36 +633,33 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Debug.Assert(IsDefinition) ' Check return type. - Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = MergeUseSiteInfo(New UseSiteInfo(Of AssemblySymbol)(Me.PrimaryDependency), DeriveUseSiteInfoFromType(Me.ReturnType)) + Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = New UseSiteInfo(Of AssemblySymbol)(Me.PrimaryDependency) - If useSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedMethod1 Then + If MergeUseSiteInfo(useSiteInfo, DeriveUseSiteInfoFromType(Me.ReturnType)) Then Return useSiteInfo End If ' Check return type custom modifiers. Dim refModifiersUseSiteInfo = DeriveUseSiteInfoFromCustomModifiers(Me.RefCustomModifiers) - If refModifiersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedMethod1 Then - Return refModifiersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, refModifiersUseSiteInfo) Then + Return useSiteInfo End If Dim typeModifiersUseSiteInfo = DeriveUseSiteInfoFromCustomModifiers(Me.ReturnTypeCustomModifiers, allowIsExternalInit:=IsInitOnly) - If typeModifiersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedMethod1 Then - Return typeModifiersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, typeModifiersUseSiteInfo) Then + Return useSiteInfo End If ' Check parameters. Dim parametersUseSiteInfo = DeriveUseSiteInfoFromParameters(Me.Parameters) - If parametersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedMethod1 Then - Return parametersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, parametersUseSiteInfo) Then + Return useSiteInfo End If - Dim errorInfo As DiagnosticInfo = If(useSiteInfo.DiagnosticInfo, - If(refModifiersUseSiteInfo.DiagnosticInfo, - If(typeModifiersUseSiteInfo.DiagnosticInfo, - parametersUseSiteInfo.DiagnosticInfo))) + Dim errorInfo As DiagnosticInfo = useSiteInfo.DiagnosticInfo ' If the member is in an assembly with unified references, ' we check if its definition depends on a type from a unified reference. @@ -694,16 +691,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' ''' Return error code that has highest priority while calculating use site error for this symbol. ''' - Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer - Get - Return ERRID.ERR_UnsupportedMethod1 - End Get - End Property + Protected Overrides Function IsHighestPriorityUseSiteError(code As Integer) As Boolean + Return code = ERRID.ERR_UnsupportedMethod1 OrElse code = ERRID.ERR_UnsupportedCompilerFeature + End Function Public NotOverridable Overrides ReadOnly Property HasUnsupportedMetadata As Boolean Get Dim info As DiagnosticInfo = GetUseSiteInfo().DiagnosticInfo - Return info IsNot Nothing AndAlso info.Code = ERRID.ERR_UnsupportedMethod1 + Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedMethod1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature) End Get End Property diff --git a/src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb index 2e4a4604268ca..77b23983ca0b2 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbol.vb @@ -995,14 +995,15 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ' Check definition. Dim definitionUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromType(Me.OriginalDefinition) - If definitionUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedType1 Then + If definitionUseSiteInfo.DiagnosticInfo IsNot Nothing AndAlso IsHighestPriorityUseSiteError(definitionUseSiteInfo.DiagnosticInfo.Code) Then Return definitionUseSiteInfo End If ' Check type arguments. Dim argsUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromTypeArguments() - Return MergeUseSiteInfo(definitionUseSiteInfo, argsUseSiteInfo) + MergeUseSiteInfo(definitionUseSiteInfo, argsUseSiteInfo) + Return definitionUseSiteInfo End Function Private Function DeriveUseSiteInfoFromTypeArguments() As UseSiteInfo(Of AssemblySymbol) @@ -1011,14 +1012,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Do For Each arg As TypeSymbol In currentType.TypeArgumentsNoUseSiteDiagnostics - If MergeUseSiteInfo(argsUseSiteInfo, DeriveUseSiteInfoFromType(arg), ERRID.ERR_UnsupportedType1) Then + If MergeUseSiteInfo(argsUseSiteInfo, DeriveUseSiteInfoFromType(arg)) Then Return argsUseSiteInfo End If Next If currentType.HasTypeArgumentsCustomModifiers Then For i As Integer = 0 To Me.Arity - 1 - If MergeUseSiteInfo(argsUseSiteInfo, DeriveUseSiteInfoFromCustomModifiers(Me.GetTypeArgumentCustomModifiers(i)), ERRID.ERR_UnsupportedType1) Then + If MergeUseSiteInfo(argsUseSiteInfo, DeriveUseSiteInfoFromCustomModifiers(Me.GetTypeArgumentCustomModifiers(i))) Then Return argsUseSiteInfo End If Next diff --git a/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb index 632da5069692e..b446c8cd44acc 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/ParameterSymbol.vb @@ -276,16 +276,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' Friend MustOverride ReadOnly Property CallerArgumentExpressionParameterIndex As Integer - Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer - Get - Return ERRID.ERR_UnsupportedType1 - End Get - End Property + Protected Overrides Function IsHighestPriorityUseSiteError(code As Integer) As Boolean + Return code = ERRID.ERR_UnsupportedType1 OrElse code = ERRID.ERR_UnsupportedCompilerFeature + End Function - Public NotOverridable Overrides ReadOnly Property HasUnsupportedMetadata As Boolean + Public Overrides ReadOnly Property HasUnsupportedMetadata As Boolean Get - Dim info As DiagnosticInfo = DeriveUseSiteInfoFromParameter(Me, HighestPriorityUseSiteError).DiagnosticInfo - Return info IsNot Nothing AndAlso info.Code = ERRID.ERR_UnsupportedType1 + Dim info As DiagnosticInfo = DeriveUseSiteInfoFromParameter(Me).DiagnosticInfo + Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedType1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature) End Get End Property diff --git a/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb index 857d89fc10f57..d8142c7960171 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/PropertySymbol.vb @@ -404,36 +404,33 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols Debug.Assert(IsDefinition) ' Check return type. - Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = MergeUseSiteInfo(New UseSiteInfo(Of AssemblySymbol)(Me.PrimaryDependency), DeriveUseSiteInfoFromType(Me.Type)) + Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = New UseSiteInfo(Of AssemblySymbol)(Me.PrimaryDependency) - If useSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedProperty1 Then + If MergeUseSiteInfo(useSiteInfo, DeriveUseSiteInfoFromType(Me.Type)) Then Return useSiteInfo End If ' Check return type custom modifiers. Dim refModifiersUseSiteInfo = DeriveUseSiteInfoFromCustomModifiers(Me.RefCustomModifiers) - If refModifiersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedProperty1 Then - Return refModifiersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, refModifiersUseSiteInfo) Then + Return useSiteInfo End If Dim typeModifiersUseSiteInfo = DeriveUseSiteInfoFromCustomModifiers(Me.TypeCustomModifiers) - If typeModifiersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedProperty1 Then - Return typeModifiersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, typeModifiersUseSiteInfo) Then + Return useSiteInfo End If ' Check parameters. Dim parametersUseSiteInfo = DeriveUseSiteInfoFromParameters(Me.Parameters) - If parametersUseSiteInfo.DiagnosticInfo?.Code = ERRID.ERR_UnsupportedProperty1 Then - Return parametersUseSiteInfo + If MergeUseSiteInfo(useSiteInfo, parametersUseSiteInfo) Then + Return useSiteInfo End If - Dim errorInfo As DiagnosticInfo = If(useSiteInfo.DiagnosticInfo, - If(refModifiersUseSiteInfo.DiagnosticInfo, - If(typeModifiersUseSiteInfo.DiagnosticInfo, - parametersUseSiteInfo.DiagnosticInfo))) + Dim errorInfo As DiagnosticInfo = useSiteInfo.DiagnosticInfo ' If the member is in an assembly with unified references, ' we check if its definition depends on a type from a unified reference. @@ -464,16 +461,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols ''' ''' Return error code that has highest priority while calculating use site error for this symbol. ''' - Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer - Get - Return ERRID.ERR_UnsupportedProperty1 - End Get - End Property + Protected Overrides Function IsHighestPriorityUseSiteError(code As Integer) As Boolean + Return code = ERRID.ERR_UnsupportedProperty1 OrElse code = ERRID.ERR_UnsupportedCompilerFeature + End Function Public NotOverridable Overrides ReadOnly Property HasUnsupportedMetadata As Boolean Get Dim info As DiagnosticInfo = GetUseSiteInfo().DiagnosticInfo - Return info IsNot Nothing AndAlso info.Code = ERRID.ERR_UnsupportedProperty1 + Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedProperty1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature) End Get End Property diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb index 22fec68b94238..ce1970087765d 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb @@ -946,21 +946,14 @@ Namespace Microsoft.CodeAnalysis.VisualBasic End Sub ''' - ''' Return error code that has highest priority while calculating use site error for this symbol. + ''' Returns true if the error code is highest priority while calculating use site error for this symbol. ''' - Protected Overridable ReadOnly Property HighestPriorityUseSiteError As Integer ' Supposed to be ERRID, but it causes inconsistent accessibility error. - Get - Return Integer.MaxValue - End Get - End Property - - Friend Function MergeUseSiteInfo(first As UseSiteInfo(Of AssemblySymbol), second As UseSiteInfo(Of AssemblySymbol)) As UseSiteInfo(Of AssemblySymbol) - MergeUseSiteInfo(first, second, HighestPriorityUseSiteError) - Return first + Protected Overridable Function IsHighestPriorityUseSiteError(code As Integer) As Boolean ' Supposed to be ERRID, but it causes inconsistent accessibility error. + Return False End Function - Friend Shared Function MergeUseSiteInfo(ByRef result As UseSiteInfo(Of AssemblySymbol), other As UseSiteInfo(Of AssemblySymbol), highestPriorityUseSiteError As Integer) As Boolean - If other.DiagnosticInfo?.Code = highestPriorityUseSiteError Then + Friend Function MergeUseSiteInfo(ByRef result As UseSiteInfo(Of AssemblySymbol), other As UseSiteInfo(Of AssemblySymbol)) As Boolean + If other.DiagnosticInfo IsNot Nothing AndAlso IsHighestPriorityUseSiteError(other.DiagnosticInfo.Code) Then result = other Return True End If @@ -978,26 +971,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Return False Else - Return result.DiagnosticInfo.Code = highestPriorityUseSiteError + Return IsHighestPriorityUseSiteError(result.DiagnosticInfo.Code) End If End Function - Friend Function DeriveUseSiteInfoFromParameter(param As ParameterSymbol, highestPriorityUseSiteError As Integer) As UseSiteInfo(Of AssemblySymbol) + Friend Function DeriveUseSiteInfoFromParameter(param As ParameterSymbol) As UseSiteInfo(Of AssemblySymbol) Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromType(param.Type) - If useSiteInfo.DiagnosticInfo?.Code = highestPriorityUseSiteError Then + If useSiteInfo.DiagnosticInfo IsNot Nothing AndAlso IsHighestPriorityUseSiteError(useSiteInfo.DiagnosticInfo.Code) Then Return useSiteInfo End If Dim refModifiersUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromCustomModifiers(param.RefCustomModifiers) - If refModifiersUseSiteInfo.DiagnosticInfo?.Code = highestPriorityUseSiteError Then + If refModifiersUseSiteInfo.DiagnosticInfo IsNot Nothing AndAlso IsHighestPriorityUseSiteError(refModifiersUseSiteInfo.DiagnosticInfo.Code) Then Return refModifiersUseSiteInfo End If Dim modifiersUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = DeriveUseSiteInfoFromCustomModifiers(param.CustomModifiers) - If modifiersUseSiteInfo.DiagnosticInfo?.Code = highestPriorityUseSiteError Then + If modifiersUseSiteInfo.DiagnosticInfo IsNot Nothing AndAlso IsHighestPriorityUseSiteError(modifiersUseSiteInfo.DiagnosticInfo.Code) Then Return modifiersUseSiteInfo End If @@ -1019,10 +1012,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Friend Function DeriveUseSiteInfoFromParameters(parameters As ImmutableArray(Of ParameterSymbol)) As UseSiteInfo(Of AssemblySymbol) Dim paramsUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = Nothing - Dim highestPriorityUseSiteError As Integer = Me.HighestPriorityUseSiteError For Each param As ParameterSymbol In parameters - If MergeUseSiteInfo(paramsUseSiteInfo, DeriveUseSiteInfoFromParameter(param, highestPriorityUseSiteError), highestPriorityUseSiteError) Then + If MergeUseSiteInfo(paramsUseSiteInfo, DeriveUseSiteInfoFromParameter(param)) Then Exit For End If Next @@ -1035,7 +1027,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic Optional allowIsExternalInit As Boolean = False ) As UseSiteInfo(Of AssemblySymbol) Dim modifiersUseSiteInfo As UseSiteInfo(Of AssemblySymbol) = Nothing - Dim highestPriorityUseSiteError As Integer = Me.HighestPriorityUseSiteError For Each modifier As CustomModifier In customModifiers Dim useSiteInfo As UseSiteInfo(Of AssemblySymbol) @@ -1046,7 +1037,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic useSiteInfo = New UseSiteInfo(Of AssemblySymbol)(ErrorFactory.ErrorInfo(ERRID.ERR_UnsupportedType1, String.Empty)) GetSymbolSpecificUnsupportedMetadataUseSiteErrorInfo(useSiteInfo) - If MergeUseSiteInfo(modifiersUseSiteInfo, useSiteInfo, highestPriorityUseSiteError) Then + If MergeUseSiteInfo(modifiersUseSiteInfo, useSiteInfo) Then Exit For End If End If @@ -1054,7 +1045,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic useSiteInfo = DeriveUseSiteInfoFromType(DirectCast(modifier, VisualBasicCustomModifier).ModifierSymbol) - If MergeUseSiteInfo(modifiersUseSiteInfo, useSiteInfo, highestPriorityUseSiteError) Then + If MergeUseSiteInfo(modifiersUseSiteInfo, useSiteInfo) Then Exit For End If Next diff --git a/src/Compilers/VisualBasic/Portable/Symbols/Symbol_Attributes.vb b/src/Compilers/VisualBasic/Portable/Symbols/Symbol_Attributes.vb index 860b150e5b5b9..accc2a1242633 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/Symbol_Attributes.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/Symbol_Attributes.vb @@ -197,6 +197,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic If arguments.Attribute.IsTargetAttribute(Me, AttributeDescription.SkipLocalsInitAttribute) Then DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.WRN_AttributeNotSupportedInVB, arguments.AttributeSyntaxOpt.Location, AttributeDescription.SkipLocalsInitAttribute.FullName) + ElseIf arguments.Attribute.IsTargetAttribute(Me, AttributeDescription.CompilerFeatureRequiredAttribute) Then + DirectCast(arguments.Diagnostics, BindingDiagnosticBag).Add(ERRID.ERR_DoNotUseCompilerFeatureRequired, arguments.AttributeSyntaxOpt.Location) End If End Sub diff --git a/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbol.vb index 8ee0405eb018b..7e5e6d7ddb021 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/TypeSymbol.vb @@ -513,16 +513,14 @@ Done: ''' ''' Return error code that has highest priority while calculating use site error for this symbol. ''' - Protected Overrides ReadOnly Property HighestPriorityUseSiteError As Integer - Get - Return ERRID.ERR_UnsupportedType1 - End Get - End Property + Protected Overrides Function IsHighestPriorityUseSiteError(code As Integer) As Boolean + Return code = ERRID.ERR_UnsupportedType1 OrElse code = ERRID.ERR_UnsupportedCompilerFeature + End Function - Public NotOverridable Overrides ReadOnly Property HasUnsupportedMetadata As Boolean + Public Overrides ReadOnly Property HasUnsupportedMetadata As Boolean Get Dim info As DiagnosticInfo = GetUseSiteInfo().DiagnosticInfo - Return info IsNot Nothing AndAlso info.Code = ERRID.ERR_UnsupportedType1 + Return info IsNot Nothing AndAlso (info.Code = ERRID.ERR_UnsupportedType1 OrElse info.Code = ERRID.ERR_UnsupportedCompilerFeature) End Get End Property diff --git a/src/Compilers/VisualBasic/Portable/VBResources.resx b/src/Compilers/VisualBasic/Portable/VBResources.resx index 0fc1c93964159..f9c5e8b50f35b 100644 --- a/src/Compilers/VisualBasic/Portable/VBResources.resx +++ b/src/Compilers/VisualBasic/Portable/VBResources.resx @@ -5650,4 +5650,10 @@ {0} '{1}' cannot implement interface '{3}' because it contains shared abstract '{2}'. - + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + \ No newline at end of file diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf index 74dbe4cd9e5b2..f95673276b56f 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.cs.xlf @@ -27,6 +27,11 @@ Typ {0} nemůže být vložený, protože má neabstraktní člen. Zvažte nastavení vlastnosti Vložit typy spolupráce na hodnotu false. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). Ve stejném adresáři nemůže být více konfiguračních souborů analyzátoru ({0}). @@ -72,6 +77,11 @@ Atribut UnmanagedCallersOnly se nepodporuje. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression výraz argumentu volajícího diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf index a23847ee1b959..e09396cb29548 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.de.xlf @@ -27,6 +27,11 @@ Der Typ "{0}" kann nicht eingebettet werden, weil er einen nicht abstrakten Member aufweist. Legen Sie die Eigenschaft "Interoptypen einbetten" ggf. auf FALSE fest. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). Dasselbe Verzeichnis ({0}) darf nicht mehrere Konfigurationsdateien des Analysetools enthalten. @@ -72,6 +77,11 @@ Das Attribut "UnmanagedCallersOnly" wird nicht unterstützt. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression Aufruferargumentausdruck diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf index 5aff11abead9e..0f417c0d3e00e 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.es.xlf @@ -27,6 +27,11 @@ El tipo "{0}" no se puede incrustar porque tiene un miembro no abstracto. Puede establecer la propiedad "Incrustar tipos de interoperabilidad" en false. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). No es posible que un mismo directorio ("{0}") contenga varios archivos de configuración del analizador. @@ -72,6 +77,11 @@ No se admite el atributo "UnmanagedCallersOnly". + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression expresión de argumento de autor de llamada diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf index aa9b5800ad529..2a45359ecc6ad 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.fr.xlf @@ -27,6 +27,11 @@ Impossible d'incorporer le type '{0}', car il a un membre non abstrait. Affectez la valeur false à la propriété 'Incorporer les types interop'. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). Plusieurs fichiers config d'analyseur ne peuvent pas figurer dans le même répertoire ('{0}'). @@ -72,6 +77,11 @@ L'attribut 'UnmanagedCallersOnly' n'est pas pris en charge. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression expression d’argument de l’appelant diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf index 49dced1ee481e..0dff509f7a273 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.it.xlf @@ -27,6 +27,11 @@ Non è possibile incorporare il tipo '{0}' perché contiene un membro non astratto. Provare a impostare la proprietà 'Incorpora tipi di interoperabilità' su false. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). La stessa directory ('{0}') non può contenere più file di configurazione dell'analizzatore. @@ -72,6 +77,11 @@ L'attributo 'UnmanagedCallersOnly' non è supportato. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression espressione passata come argomento del chiamante diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf index 366b22b30ed17..64442f73c17bf 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ja.xlf @@ -27,6 +27,11 @@ 型 '{0}' には非抽象メンバーがあるため、この型を埋め込むことはできません。'相互運用型の埋め込み' プロパティを false に設定することをご検討ください。 + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). 複数のアナライザー構成ファイルを同じディレクトリに入れることはできません ('{0}')。 @@ -72,6 +77,11 @@ 'UnmanagedCallersOnly' 属性はサポートされていません。 + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression 呼び出し元の引数式 diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf index 04c427b770613..f323fafb03155 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ko.xlf @@ -27,6 +27,11 @@ '{0}' 형식에는 비추상 멤버가 있으므로 해당 형식을 포함할 수 없습니다. 'Interop 형식 포함' 속성을 false로 설정해보세요. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). 분석기 구성 파일 여러 개가 동일한 디렉터리('{0}')에 있을 수 없습니다. @@ -72,6 +77,11 @@ 'UnmanagedCallersOnly' 특성은 지원되지 않습니다. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression 호출자 인수 표현식 diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf index 5f6b7884f04d0..92a76b8aaa915 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pl.xlf @@ -27,6 +27,11 @@ Nie można osadzić typu „{0}”, ponieważ ma nieabstrakcyjną składową. Rozważ ustawienie wartości false dla właściwości „Osadź typy międzyoperacyjne”. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). Wiele plików konfiguracji analizatora nie może znajdować się w tym samym katalogu („{0}”). @@ -72,6 +77,11 @@ Atrybut „UnmanagedCallersOnly” jest nieobsługiwany. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression wyrażenie argumentu wywołującego diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf index 206d8737e4cb4..c41ff58308bec 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.pt-BR.xlf @@ -27,6 +27,11 @@ O tipo '{0}' não pode ser inserido porque tem um membro que não é abstrato. Considere a definição da propriedade 'Inserir Tipos de Interoperabilidade' como false. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). Não é possível que haja vários arquivos de configuração do analisador no mesmo diretório ('{0}'). @@ -72,6 +77,11 @@ Não há suporte para o atributo 'UnmanagedCallersOnly'. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression expressão do argumento do chamador diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf index fb9068dd3eff5..87fda78fe33be 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.ru.xlf @@ -27,6 +27,11 @@ Не удается внедрить тип "{0}", так как он имеет неабстрактный член. Попробуйте задать для свойства "Внедрить типы взаимодействия" значение false. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). В одном каталоге ("{0}") не может находиться несколько файлов конфигурации анализатора. @@ -72,6 +77,11 @@ Атрибут "UnmanagedCallersOnly" не поддерживается. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression выражение аргумента вызывающего diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf index e6bbcbc2efa53..a493c72740a9d 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.tr.xlf @@ -27,6 +27,11 @@ '{0}' türünün soyut olmayan bir üyesi olduğundan bu tür eklenemiyor. 'Embed Interop Types' özelliğini false olarak ayarlamayı deneyin. + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). Birden çok çözümleyici yapılandırma dosyası aynı dizinde ('{0}') olamaz. @@ -72,6 +77,11 @@ 'UnmanagedCallersOnly' özniteliği desteklenmez. + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression çağıran bağımsız değişken ifadesi diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf index 288055d74cc81..d79b4ca9af8f3 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hans.xlf @@ -27,6 +27,11 @@ 无法嵌入类型“{0}”,因为它有非抽象成员。请考虑将“嵌入互操作类型”属性设置为 false。 + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). 多个分析器配置文件不能位于同一目录({0})中。 @@ -72,6 +77,11 @@ 不支持 "UnmanagedCallersOnly" 属性。 + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression 调用方参数表达式 diff --git a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf index 3bf828f847415..4293a6bade1dc 100644 --- a/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf +++ b/src/Compilers/VisualBasic/Portable/xlf/VBResources.zh-Hant.xlf @@ -27,6 +27,11 @@ 因為類型 '{0}' 有非抽象成員,所以無法內嵌。請考慮將 [內嵌 Interop 類型] 屬性設為 false。 + + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + Multiple analyzer config files cannot be in the same directory ('{0}'). 多個分析器組態檔無法處於相同目錄 ('{0}') 中。 @@ -72,6 +77,11 @@ 不支援 'UnmanagedCallersOnly' 屬性。 + + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + '{0}' requires compiler feature '{1}', which is not supported by this version of the Visual Basic compiler. + + caller argument expression 呼叫者引數運算式 diff --git a/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/VisualBasicCompilerFeatureRequiredTests.vb b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/VisualBasicCompilerFeatureRequiredTests.vb new file mode 100644 index 0000000000000..f1a9c4e3941c2 --- /dev/null +++ b/src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/Metadata/PE/VisualBasicCompilerFeatureRequiredTests.vb @@ -0,0 +1,739 @@ +' Licensed to the .NET Foundation under one or more agreements. +' The .NET Foundation licenses this file to you under the MIT license. +' See the LICENSE file in the project root for more information. + +Imports Microsoft.CodeAnalysis +Imports Microsoft.CodeAnalysis.CodeGen +Imports Microsoft.CodeAnalysis.CSharp.UnitTests.Symbols +Imports Microsoft.CodeAnalysis.Test.Utilities +Imports Microsoft.CodeAnalysis.UnitTests +Imports Microsoft.CodeAnalysis.VisualBasic +Imports Microsoft.CodeAnalysis.VisualBasic.Symbols +Imports Microsoft.CodeAnalysis.VisualBasic.UnitTests + +Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests + + Public Class VisualBasicCompilerFeatureRequiredTests + Inherits BaseCompilerFeatureRequiredTests(Of VisualBasicCompilation, XElement) + + Private Class CompilerFeatureRequiredTests_VisualBasic + Inherits BasicTestBase + End Class + + Private ReadOnly _testBase As New CompilerFeatureRequiredTests_VisualBasic() + + Friend Overrides Function VisualizeRealIL(peModule As IModuleSymbol, methodData As CompilationTestData.MethodData, markers As IReadOnlyDictionary(Of Integer, String), areLocalsZeroed As Boolean) As String + Return _testBase.VisualizeRealIL(peModule, methodData, markers, areLocalsZeroed) + End Function + + Protected Overrides Function GetUsage() As XElement + Return + + + + End Function + + Protected Overrides Function CreateCompilationWithIL(source As XElement, ilSource As String) As VisualBasicCompilation + Return CreateCompilationWithCustomILSource(source, ilSource) + End Function + + Protected Overrides Function CreateCompilation(source As XElement, references() As MetadataReference) As VisualBasicCompilation + Return CompilationUtils.CreateCompilation(source, references) + End Function + + Protected Overrides Function CompileAndVerify(compilation As VisualBasicCompilation) As CompilationVerifier + Return _testBase.CompileAndVerify(compilation) + End Function + + Protected Overrides Sub AssertNormalErrors(comp As VisualBasicCompilation) + comp.AssertTheseDiagnostics( + + ) + + Dim onType = comp.GetTypeByMetadataName("OnType") + Assert.True(onType.HasUnsupportedMetadata) + Assert.True(onType.GetMember(Of MethodSymbol)("M").HasUnsupportedMetadata) + + Dim onMethod = comp.GetTypeByMetadataName("OnMethod") + Assert.False(onMethod.HasUnsupportedMetadata) + Assert.True(onMethod.GetMember(Of MethodSymbol)("M").HasUnsupportedMetadata) + + Dim onMethodReturn = comp.GetTypeByMetadataName("OnMethodReturn") + Assert.False(onMethodReturn.HasUnsupportedMetadata) + Assert.True(onMethodReturn.GetMember(Of MethodSymbol)("M").HasUnsupportedMetadata) + + Dim onParameter = comp.GetTypeByMetadataName("OnParameter") + Assert.False(onParameter.HasUnsupportedMetadata) + Dim onParameterMethod = onParameter.GetMember(Of MethodSymbol)("M") + Assert.True(onParameterMethod.HasUnsupportedMetadata) + Assert.True(onParameterMethod.Parameters(0).HasUnsupportedMetadata) + + Dim onField = comp.GetTypeByMetadataName("OnField") + Assert.False(onField.HasUnsupportedMetadata) + Assert.True(onField.GetMember(Of FieldSymbol)("Field").HasUnsupportedMetadata) + + Dim onProperty = comp.GetTypeByMetadataName("OnProperty") + Assert.False(onProperty.HasUnsupportedMetadata) + Assert.True(onProperty.GetMember(Of PropertySymbol)("Property").HasUnsupportedMetadata) + + Dim onPropertyGetter = comp.GetTypeByMetadataName("OnPropertyGetter") + Assert.False(onPropertyGetter.HasUnsupportedMetadata) + Dim onPropertyGetterProperty = onPropertyGetter.GetMember(Of PropertySymbol)("Property") + Assert.False(onPropertyGetterProperty.HasUnsupportedMetadata) + Assert.False(onPropertyGetterProperty.SetMethod.HasUnsupportedMetadata) + Assert.True(onPropertyGetterProperty.GetMethod.HasUnsupportedMetadata) + + Dim onPropertySetter = comp.GetTypeByMetadataName("OnPropertySetter") + Assert.False(onPropertySetter.HasUnsupportedMetadata) + Dim onPropertySetterProperty = onPropertySetter.GetMember(Of PropertySymbol)("Property") + Assert.False(onPropertySetterProperty.HasUnsupportedMetadata) + Assert.True(onPropertySetterProperty.SetMethod.HasUnsupportedMetadata) + Assert.False(onPropertySetterProperty.GetMethod.HasUnsupportedMetadata) + + Dim onEvent = comp.GetTypeByMetadataName("OnEvent") + Assert.False(onEvent.HasUnsupportedMetadata) + Assert.True(onEvent.GetMember(Of EventSymbol)("Event").HasUnsupportedMetadata) + + Dim onEventAdder = comp.GetTypeByMetadataName("OnEventAdder") + Assert.False(onEventAdder.HasUnsupportedMetadata) + Dim onEventAdderEvent = onEventAdder.GetMember(Of EventSymbol)("Event") + Assert.False(onEventAdderEvent.HasUnsupportedMetadata) + Assert.True(onEventAdderEvent.AddMethod.HasUnsupportedMetadata) + Assert.False(onEventAdderEvent.RemoveMethod.HasUnsupportedMetadata) + + Dim onEventRemover = comp.GetTypeByMetadataName("OnEventRemover") + Assert.False(onEventRemover.HasUnsupportedMetadata) + Dim onEventRemoverEvent = onEventRemover.GetMember(Of EventSymbol)("Event") + Assert.False(onEventRemoverEvent.HasUnsupportedMetadata) + Assert.False(onEventRemoverEvent.AddMethod.HasUnsupportedMetadata) + Assert.True(onEventRemoverEvent.RemoveMethod.HasUnsupportedMetadata) + + Dim onEnum = comp.GetTypeByMetadataName("OnEnum") + Assert.True(onEnum.HasUnsupportedMetadata) + + Dim onEnumMember = comp.GetTypeByMetadataName("OnEnumMember") + Assert.False(onEnumMember.HasUnsupportedMetadata) + Assert.True(onEnumMember.GetMember(Of FieldSymbol)("A").HasUnsupportedMetadata) + + Dim onClassTypeParameter = comp.GetTypeByMetadataName("OnClassTypeParameter`1") + Assert.True(onClassTypeParameter.HasUnsupportedMetadata) + Assert.True(onClassTypeParameter.TypeParameters(0).HasUnsupportedMetadata) + + Dim onMethodTypeParameter = comp.GetTypeByMetadataName("OnMethodTypeParameter") + Assert.False(onMethodTypeParameter.HasUnsupportedMetadata) + Dim onMethodTypeParameterMethod = onMethodTypeParameter.GetMember(Of MethodSymbol)("M") + Assert.True(onMethodTypeParameterMethod.HasUnsupportedMetadata) + Assert.True(onMethodTypeParameterMethod.TypeParameters(0).HasUnsupportedMetadata) + + Dim onDelegateType = comp.GetTypeByMetadataName("OnDelegateType") + Assert.True(onDelegateType.HasUnsupportedMetadata) + + Dim onIndexedPropertyParameter = comp.GetTypeByMetadataName("OnIndexedPropertyParameter") + Assert.False(onIndexedPropertyParameter.HasUnsupportedMetadata) + Assert.True(onIndexedPropertyParameter.GetMember(Of MethodSymbol)("get_Property").Parameters(0).HasUnsupportedMetadata) + Assert.True(onIndexedPropertyParameter.GetMember(Of MethodSymbol)("set_Property").Parameters(0).HasUnsupportedMetadata) + + Dim onThisParameterIndexer = comp.GetTypeByMetadataName("OnThisIndexerParameter") + Assert.False(onThisParameterIndexer.HasUnsupportedMetadata) + Dim indexer = onThisParameterIndexer.GetMember(Of PropertySymbol)("Item") + Assert.True(indexer.HasUnsupportedMetadata) + Assert.True(indexer.Parameters(0).HasUnsupportedMetadata) + End Sub + + Protected Overrides Sub AssertModuleErrors(comp As VisualBasicCompilation, ilRef As MetadataReference) + comp.AssertTheseDiagnostics( + + ) + + Assert.True(comp.GetReferencedAssemblySymbol(ilRef).Modules.Single().HasUnsupportedMetadata) + End Sub + + Protected Overrides Sub AssertAssemblyErrors(comp As VisualBasicCompilation, ilRef As MetadataReference) + comp.AssertTheseDiagnostics( + + ) + + Assert.True(comp.GetReferencedAssemblySymbol(ilRef).HasUnsupportedMetadata) + End Sub + + + Public Sub Application() + Dim compilation = CompilationUtils.CreateCompilation( + +Public Class OnType +End Class + +Public Class OnMethod + + Public Sub OnMethod() + End Sub +End Class + +Public Class OnMethodReturn + Public Function OnMethodReturn() As Integer + Return 1 + End Function +End Class + +Public Class OnField + + Public Field As Integer +End Class + +Public Class OnProperty + + Public Property Prop As Integer +End Class + +Public Class OnPropertySetter + Public Property Prop As Integer + Get + Return 1 + End Get + + Set + End Set + End Property +End Class + +Public Class OnPropertyGetter + Public Property Prop As Integer + + Get + Return 1 + End Get + Set + End Set + End Property +End Class + +Public Class OnEvent + + Public Event [Event] As Action +End Class + +Public Class OnEventAdder + Public Custom Event [Event] As Action + + AddHandler(value As Action) + End AddHandler + RemoveHandler(value As Action) + End RemoveHandler + RaiseEvent + End RaiseEvent + End Event +End Class + +Public Class OnEventRemover + Public Custom Event [Event] As Action + AddHandler(value As Action) + End AddHandler + + RemoveHandler(value As Action) + End RemoveHandler + RaiseEvent + End RaiseEvent + End Event +End Class + +Public Class OnEventRaiseEvent + Public Custom Event [Event] As Action + AddHandler(value As Action) + End AddHandler + RemoveHandler(value As Action) + End RemoveHandler + + RaiseEvent + End RaiseEvent + End Event +End Class + + +Public Enum OnEnum + A +End Enum + +Public Enum OnEnumMember + A +End Enum + + +Public Delegate Sub OnDelegate() +]]> + + + + Public Class CompilerFeatureRequiredAttribute + Inherits Attribute + + Public Sub New(featureName As String) + FeatureName = featureName + End Sub + + Public ReadOnly Property FeatureName As String + + Public Property IsOptional As Boolean + End Class +End Namespace +]]> + + + ) + + compilation.AssertTheseDiagnostics( + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + Public Function OnMethodReturn() As Integer + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + A + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +BC37320: 'System.Runtime.CompilerServices.CompilerFeatureRequiredAttribute' is reserved for compiler usage only. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +]]>) + End Sub + End Class +End Namespace