Skip to content

Commit b8bf7a8

Browse files
authored
Block manual application of MethodImplAttribute.Async to methods (#80031)
Block manual application of MethodImplAttribute.Async to methods, except for specific corelib locations.
1 parent 7a96051 commit b8bf7a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+456
-6
lines changed

src/Compilers/CSharp/Portable/CSharpResources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8228,4 +8228,8 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
82288228
<data name="ERR_ExtensionBlockCollision" xml:space="preserve">
82298229
<value>This extension block collides with another extension block. They result in conflicting content-based type names in metadata, so must be in separate enclosing static classes.</value>
82308230
</data>
8231+
<data name="ERR_MethodImplAttributeAsyncCannotBeUsed" xml:space="preserve">
8232+
<value>'MethodImplAttribute.Async' cannot be manually applied to methods. Mark the method 'async'.</value>
8233+
<remarks>'MethodImplAttribute.Async' and 'async' are not localizable.</remarks>
8234+
</data>
82318235
</root>

src/Compilers/CSharp/Portable/Errors/ErrorCode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,7 @@ internal enum ErrorCode
24242424
ERR_FeatureNotAvailableInVersion14 = 9327,
24252425
ERR_UnsupportedFeatureInRuntimeAsync = 9328,
24262426
ERR_ExtensionBlockCollision = 9329,
2427+
ERR_MethodImplAttributeAsyncCannotBeUsed = 9330,
24272428

24282429
// Note: you will need to do the following after adding errors:
24292430
// 1) Update ErrorFacts.IsBuildOnlyDiagnostic (src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs)

src/Compilers/CSharp/Portable/Errors/ErrorFacts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,7 @@ or ErrorCode.ERR_InterpolatedStringHandlerArgumentDisallowed
25352535
or ErrorCode.ERR_MemberNameSameAsExtendedType
25362536
or ErrorCode.ERR_FeatureNotAvailableInVersion14
25372537
or ErrorCode.ERR_ExtensionBlockCollision
2538+
or ErrorCode.ERR_MethodImplAttributeAsyncCannotBeUsed
25382539
=> false,
25392540
};
25402541
#pragma warning restore CS8524 // The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value.

src/Compilers/CSharp/Portable/Errors/MessageProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public override void ReportDuplicateMetadataReferenceWeak(DiagnosticBag diagnost
234234

235235
// pseudo-custom attributes:
236236
public override int ERR_PermissionSetAttributeFileReadError => (int)ErrorCode.ERR_PermissionSetAttributeFileReadError;
237+
public override int ERR_MethodImplAttributeAsyncCannotBeUsed => (int)ErrorCode.ERR_MethodImplAttributeAsyncCannotBeUsed;
237238

238239
// PDB Writer:
239240
public override int ERR_EncodinglessSyntaxTree => (int)ErrorCode.ERR_EncodinglessSyntaxTree;

src/Compilers/CSharp/Portable/Symbols/Source/SourceMethodSymbolWithAttributes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
535535
}
536536
else if (attribute.IsTargetAttribute(AttributeDescription.MethodImplAttribute))
537537
{
538-
AttributeData.DecodeMethodImplAttribute<MethodWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation>(ref arguments, MessageProvider.Instance);
538+
AttributeData.DecodeMethodImplAttribute<MethodWellKnownAttributeData, AttributeSyntax, CSharpAttributeData, AttributeLocation>(ref arguments, MessageProvider.Instance, this.ContainingType);
539539
}
540540
else if (attribute.IsTargetAttribute(AttributeDescription.DllImportAttribute))
541541
{

src/Compilers/CSharp/Portable/Symbols/TypeSymbol.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,6 +2520,8 @@ internal ITypeSymbol GetITypeSymbol(CodeAnalysis.NullableAnnotation nullableAnno
25202520

25212521
SpecialType ITypeSymbolInternal.SpecialType => this.SpecialType;
25222522

2523+
ExtendedSpecialType ITypeSymbolInternal.ExtendedSpecialType => this.ExtendedSpecialType;
2524+
25232525
bool ITypeSymbolInternal.IsReferenceType => this.IsReferenceType;
25242526

25252527
bool ITypeSymbolInternal.IsValueType => this.IsValueType;

src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)