Unsafe evolution spec: consolidate attribute declaration diagnostics#9999
Merged
Conversation
jjonescz
commented
Feb 17, 2026
| - fields, | ||
| - destructors. | ||
| The compiler will emit a warning if `RequiresUnsafe` is used under the legacy memory safety rules and an error if it is applied to unsupported symbol kinds | ||
| (note that this excludes symbol kinds that should be banned already by `AttributeUsageAttribute` on the attribute's definition): |
Member
Author
There was a problem hiding this comment.
Inspired by UnscopedRefAttribute - it also reports a custom error for locations like static methods where it doesn't make sense but relies on AttributeTargets error elsewhere:
using System.Diagnostics.CodeAnalysis;
[UnscopedRef] // error CS0592: Attribute 'UnscopedRef' is not valid on this declaration type. It is only valid on 'method, property, indexer, parameter' declarations.
class C
{
[UnscopedRef] // error CS9101: UnscopedRefAttribute can only be applied to struct or virtual interface instance methods and properties, and cannot be applied to constructors or init-only members.
static void M() { }
}
jcouv
reviewed
Feb 17, 2026
|
|
||
| ### `new()` constraint | ||
|
|
||
| Do we want to support `new()` with *requires-unsafe* (something we currently don't seem to support in the compiler for other features, like `Obsolete`)? |
Member
There was a problem hiding this comment.
Consider adding a code snippet to illustrate the scenario/question. It was not clear to me whether this is the same issue described in next section or a separate question
Member
Author
There was a problem hiding this comment.
The example in the next section is just a bit extended version of this, but I can add a simpler example just for this section too. Thanks.
jcouv
approved these changes
Feb 17, 2026
jjonescz
added a commit
to dotnet/roslyn
that referenced
this pull request
Feb 24, 2026
… some cleanup (#82456) Test plan: #81207 Related speclet update: dotnet/csharplang#9999
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.