Repository navigation
Report ST023 when a ref-struct signature has no holder types - #356
Merged
Merged
Conversation
A stunt with a Span or other ref struct in a signature passes it through StructRef<T>, SpanRef<T> or ReadOnlySpanRef<T>. SignatureRefGenerator adds those only on a runtime with by-ref-like generics (.NET 9) and with C# 13 or later, but the stunt generator used them regardless, so other projects failed inside generated code with no Stunts diagnostic. UnsafeSignatureAnalyzer now reports ST023 at the call that asks for the stunt, and the message says what to change: the target framework, the LangVersion, or both. It is reported beside ST009 when both apply. RefStructHolders holds the condition for the generator, the analyzer and CSharpAot, whose ST015 warning only checked the runtime. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-authored-by: CodeAlta <noreply@codealta.io>
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.
A stunt with a
Span<T>or other ref struct in a signature passes it throughStructRef<T>,SpanRef<T>orReadOnlySpanRef<T>.SignatureRefGeneratoradds those types only on a runtime with by-ref-like generics (.NET 9) and with C# 13 or later, but the stunt generator used them regardless. A project on .NET 8, or on .NET 9 or later withLangVersion9 to 12, failed with compiler errors inside generated code and no Stunts diagnostic.Changes
UnsafeSignatureAnalyzerreports the new errorST023at the call that asks for the stunt. The message says what to change: target .NET 9 or later, setLangVersionto 13 or later, or both. It is reported besideST009when unsafe blocks are also off. Pointer-only signatures are not affected.RefStructHoldersholds the runtime and language-version condition forSignatureRefGenerator, the analyzer andCSharpAot. The Native AOTST015warning about ref structs only checked the runtime, and now also covers C# 9 to 12.ST023is documented indocs/guide/diagnostics.md; theST015rows indocs/guide/aot.mdandreadme.mdmention C# 13.Tests
CodeAnalysis/ST009_UnsafeSignature.cscovers each message, the first supported language version (C# 13), an interface property, pointers, andST009together withST023. The runtime case uses a small core library declared in source, withoutRuntimeFeature.ByRefLikeGenerics.StuntGeneratorTests.WarnsAboutRefStructsWithoutHoldersForAotcoversST015with C# 12. The full suite passes (397 tests).Not covered
Ref-struct constructor parameters and stunts registered with
[assembly: Stunt<T>]are not analyzed, forST009either.This pull request was created by CodeAlta.
🤖 Generated with Claude Code