Repository navigation
Report ST009 and ST023 for constructors and assembly registrations - #358
Merged
Merged
Conversation
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>
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.
UnsafeSignatureAnalyzeronly 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
'Buffer.Buffer'in the message. It skips them whenEnableCompileTimeStuntsis explicitlyfalse: run-time stunts do not intercept constructors.[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 toSymbolExtensions.IsRegistrationAttribute, shared with the generator, and the analyzer has a protected constructor that takes a custom registration attribute.DelegateScaffoldpasses the arguments ofInvoketoMethodInvocation.Createwithout holders, so a ref struct in a delegate signature fails withCS9244under any setting, and the fixesST009andST023name would not help. The analyzer now skips delegate types explicitly, so framework delegates such asSpanAction<T, TArg>no longer get an accidental report throughBeginInvoke.ST015about ref structs is removed. With registrations covered it repeatsST023, which is an error. It goes with its cache flag, its rows indocs/guide/aot.mdandreadme.md, and the by-ref-like generics input ofStuntFingerprint, which only that check read.Tests
CodeAnalysis/ST009_UnsafeSignature.cshas 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 currentmain, which only added packaging targets and a readme.🤖 Generated with Claude Code
This pull request was created by CodeAlta.