Allow users to define EmbeddedAttribute#76523
Conversation
…ser-defined-embedded * origin/source-gen-warning: Additional testing Add tests
|
@dotnet/roslyn-compiler for review. I'll propose a source-generation API to allow authors to create this API easily, but this change can go in separately. |
|
Done with review pass (commit 8) #Closed |
…tself didn't have one applied to it.
|
@AlekseyTs I believe I've address your feedback, thanks! |
|
|
||
| ***Introduced in Visual Studio 2022 version 17.13*** | ||
|
|
||
| The compiler now validates the shape of `Microsoft.CodeAnalysis.EmbeddedAttribute` when declared in source. Previously, the compiler |
There was a problem hiding this comment.
Unrelated to the PR: it's not clear to me what the Microsoft.CodeAnalysis.EmbeddedAttribute does. Is that documented somewhere?
There was a problem hiding this comment.
Not documented afaik, though we will when we add the SG API. It prevents the compiler from resolving the type outside the current compilation. It's how the compiler itself gets around the "type defined in multiple assemblies" issues when it needs to synthesize an attribute.
|
Done with review pass (commit 11) #Closed |
|
@AlekseyTs @cston for another review pass |
* Work on embedded attribute recognition in source * Add tests * Additional testing * Refactoring for simplicity * Always validate in source, and document breaking change * Typo * Update test * Synthesize an application of EmbeddedAttribute if EmbeddedAttribute itself didn't have one applied to it. * Add VB validation implementation. * More PR feedback. * PR feedback * Minor typo and feedback
Alternative approach to #71546. Today, our enforcement of whether to allow users to define
Microsoft.CodeAnalysis.EmbeddedAttributeis inconsistent; if we need to generate it, we error if the user defines one. But if the we don't need to generate it (as we increasingly do not since .NET 6), we allow the user to define their own version. This PR standardizes our enforcement, and enables the compiler to use the user-declared attribute instead generating one. We also document the breaking change from the standardized enforcement.