8000 Report ST023 when a ref-struct signature has no holder types by kzu · Pull Request #356 · devlooped/stunts · GitHub
[go: up one dir, main page]

Skip to content

Report ST023 when a ref-struct signature has no holder types - #356

Merged
kzu merged 1 commit into
mainfrom
alta/perky-quince-pvgh
Nov 29, 2026
Merged

kzu merged 1 commit into
mainfrom
alta/perky-quince-pvgh

Conversation

@kzu
@kzu kzu commented Nov 29, 2026
Copy link
Copy Markdown
Member

A stunt with a Span<T> or other ref struct in a signature passes it through StructRef<T>, SpanRef<T> or ReadOnlySpanRef<T>. SignatureRefGenerator adds 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 with LangVersion 9 to 12, failed with compiler errors inside generated code and no Stunts diagnostic.

Changes

  • UnsafeSignatureAnalyzer reports the new error ST023 at the call that asks for the stunt. The message says what to change: target .NET 9 or later, set LangVersion to 13 or later, or both. It is reported beside ST009 when unsafe blocks are also off. Pointer-only signatures are not affected.
  • RefStructHolders holds the runtime and language-version condition for SignatureRefGenerator, the analyzer and CSharpAot. The Native AOT ST015 warning about ref structs only checked the runtime, and now also covers C# 9 to 12.
  • ST023 is documented in docs/guide/diagnostics.md; the ST015 rows in docs/guide/aot.md and readme.md mention C# 13.

Tests

CodeAnalysis/ST009_UnsafeSignature.cs covers each message, the first supported language version (C# 13), an interface property, pointers, and ST009 together with ST023. The runtime case uses a small core library declared in source, without RuntimeFeature.ByRefLikeGenerics. StuntGeneratorTests.WarnsAboutRefStructsWithoutHoldersForAot covers ST015 with C# 12. The full suite passes (397 tests).

Not covered

Ref-struct constructor parameters and stunts registered with [assembly: Stunt<T>] are not analyzed, for ST009 either.

This pull request was created by CodeAlta.

🤖 Generated with Claude Code

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>
@kzu kzu added the enhancement New feature or request label Nov 29, 2026
@kzu
kzu enabled auto-merge (rebase) November 29, 2026 04:38
@kzu
kzu merged commit 15b03d7 into main Nov 29, 2026
6 checks passed
@kzu
kzu deleted the alta/perky-quince-pvgh branch November 29, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0