Skip to content

Add AttributeUsage to EmbeddedAttribute#79942

Closed
michha wants to merge 2 commits intodotnet:mainfrom
michha:patch-1
Closed

Add AttributeUsage to EmbeddedAttribute#79942
michha wants to merge 2 commits intodotnet:mainfrom
michha:patch-1

Conversation

@michha
Copy link
Contributor

@michha michha commented Aug 18, 2025

prevents warning CA1018: Specify AttributeUsage on EmbeddedAttribute

EmbeddedAttribute was introduced in #76583

prevents warning CA1018: Specify AttributeUsage on EmbeddedAttribute
@michha michha requested a review from a team as a code owner August 18, 2025 10:43
@dotnet-policy-service dotnet-policy-service bot added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Aug 18, 2025
@333fred
Copy link
Member

333fred commented Aug 18, 2025

@dotnet/roslyn-compiler for a second review.

@michha
Copy link
Contributor Author

michha commented Aug 18, 2025

@333fred could you please assist me with this error?

Build https://dev.azure.com/dnceng-public/public/_build/results?buildId=1125466&view=logs&j=644ea285-4692-54f6-2965-667c9562a0e2&t=b2948985-b3d8-5780-7b2b-b582fd83c893&l=97 failed with

  Failed Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests.SourceGeneration.GeneratorDriverTests.IncrementalGenerator_PostInit_AddEmbeddedAttributeSource_Adds [17 ms]
  Error Message:
   
Expected:
Actual:
                // /datadisks/disk1/work/A3BA09A1/t/RoslynTests/Microsoft.CodeAnalysis.Test.Utilities/Roslyn.Test.Utilities.TestGenerators.PipelineCallbackGenerator2/Microsoft.CodeAnalysis.EmbeddedAttribute.cs(3,6): error CS0579: Duplicate 'global::System.AttributeUsage' attribute
                //     [global::System.AttributeUsage(global::System.AttributeTargets.All)]
                Diagnostic(ErrorCode.ERR_DuplicateAttribute, "global::System.AttributeUsage").WithArguments("global::System.AttributeUsage").WithLocation(3, 6)
Diff:
++>                 Diagnostic(ErrorCode.ERR_DuplicateAttribute, "global::System.AttributeUsage").WithArguments("global::System.AttributeUsage").WithLocation(3, 6)
  Stack Trace:
     at Microsoft.CodeAnalysis.DiagnosticExtensions.Verify(IEnumerable`1 actual, DiagnosticDescription[] expected, Boolean errorCodeOnly) in /_/src/Compilers/Test/Core/Diagnostics/DiagnosticExtensions.cs:line 99
   at Microsoft.CodeAnalysis.DiagnosticExtensions.Verify(IEnumerable`1 actual, DiagnosticDescription[] expected) in /_/src/Compilers/Test/Core/Diagnostics/DiagnosticExtensions.cs:line 48
   at Microsoft.CodeAnalysis.DiagnosticExtensions.Verify(ImmutableArray`1 actual, DiagnosticDescription[] expected) in /_/src/Compilers/Test/Core/Diagnostics/DiagnosticExtensions.cs:line 63
   at Microsoft.CodeAnalysis.DiagnosticExtensions.VerifyDiagnostics[TCompilation](TCompilation c, DiagnosticDescription[] expected) in /_/src/Compilers/Test/Core/Diagnostics/DiagnosticExtensions.cs:line 109
   at Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests.SourceGeneration.GeneratorDriverTests.IncrementalGenerator_PostInit_AddEmbeddedAttributeSource_Adds() in /_/src/Compilers/CSharp/Test/Semantic/SourceGeneration/GeneratorDriverTests.cs:line 2537
   at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
   at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

@333fred
Copy link
Member

333fred commented Aug 19, 2025

Ah right, this is not possible; if multiple generators add the attribute, they'll each have AttributeUsage. This approach cannot be taken.

Likely what we should do is mark the generated file as generated, by including an // <auto-generated/> at the top. Let's do that in a separate PR.

@333fred 333fred closed this Aug 19, 2025
@michha michha deleted the patch-1 branch August 20, 2025 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants