Skip to content

Report ST009 and ST023 for constructors and assembly registrations - #358

Merged
kzu merged 1 commit into
mainfrom
alta/windy-grove-7zs6
Nov 29, 2026
Merged

kzu merged 1 commit into
mainfrom
alta/windy-grove-7zs6

Conversation

@kzu

@kzu kzu commented Nov 29, 2026

Copy link
Copy Markdown
Member

UnsafeSignatureAnalyzer only looked at the overridable and interface members of the stunts asked for by a call, so two paths still failed inside generated code with no Stunts diagnostic.

Changes

  • Constructors. A compile-time stunt intercepts each accessible constructor of its base class, with the same holders and unsafe code as a method. The analyzer now walks those constructors and names them as 'Buffer.Buffer' in the message. It skips them when EnableCompileTimeStunts is explicitly false: run-time stunts do not intercept constructors.
  • Assembly registrations. A stunt asked for with [assembly: Stunt<T>] was never analyzed. The registration attributes of the assembly are now analyzed too, and the diagnostic is reported at the attribute. The check that recognizes the attribute moves to SymbolExtensions.IsRegistrationAttribute, shared with the generator, and the analyzer has a protected constructor that takes a custom registration attribute.
  • Delegates are left out on purpose. DelegateScaffold passes the arguments of Invoke to MethodInvocation.Create without holders, so a ref struct in a delegate signature fails with CS9244 under any setting, and the fixes ST009 and ST023 name would not help. The analyzer now skips delegate types explicitly, so framework delegates such as SpanAction<T, TArg> no longer get an accidental report through BeginInvoke.
  • ST015 about ref structs is removed. With registrations covered it repeats ST023, which is an error. It goes with its cache flag, its rows in docs/guide/aot.md and readme.md, and the by-ref-like generics input of StuntFingerprint, which only that check read.

Tests

CodeAnalysis/ST009_UnsafeSignature.cs has eight new cases: constructors (reported for both diagnostics, not reported for run-time stunts or inaccessible constructors), registrations (both diagnostics, their location at the attribute, no report when supported) and delegates. The unit test suite passed locally (404 tests) before the rebase onto the current main, which only added packaging targets and a readme.

🤖 Generated with Claude Code

This pull request was created by CodeAlta.

UnsafeSignatureAnalyzer only looked at the overridable and interface
members of the stunts asked for by a call, so two paths still failed
inside generated code with no Stunts diagnostic:

- A compile-time stunt intercepts each accessible constructor of its
  base class, with the same holders and unsafe code as a method. The
  analyzer now walks those constructors, unless compile-time stunts are
  explicitly off: run-time stunts do not intercept constructors.
- A stunt asked for with [assembly: Stunt<T>] was never analyzed. The
  registration attributes of the assembly are now analyzed too, and the
  diagnostic is reported at the attribute. The check that recognizes the
  attribute moves to SymbolExtensions.IsRegistrationAttribute, shared
  with the generator.

Delegate stunts are left out on purpose: DelegateScaffold passes the
arguments of Invoke to MethodInvocation.Create without holders, so a ref
struct in a delegate signature fails with CS9244 under any setting, and
the fixes ST009 and ST023 name would not help.

With registrations covered, the ST015 warning about ref structs repeats
ST023, an error: it is removed with its cache flag, its rows in the
docs, and the by-ref-like generics input of the fingerprint, which only
that check read.

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:58
@kzu
kzu merged commit 6fe0714 into main Nov 29, 2026
6 checks passed
@kzu
kzu deleted the alta/windy-grove-7zs6 branch November 29, 2026 05:06
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