-
-
Notifications
You must be signed in to change notification settings - Fork 108
fix: prevent interface implementation methods from being converted to async #4349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… async Methods that implement interface members should NOT have their signatures converted to async Task because this would break the interface implementation contract. The fix uses a two-pass approach: 1. Before syntax modifications, collect all methods that implement interface members using semantic analysis (via semantic model) 2. During async signature rewriting, skip methods identified as interface implementations Also adds ref/out/in parameter check to prevent async conversion of methods with those parameter types (which cannot be async). Fixes #4342 Co-Authored-By: Claude Opus 4.5 <[email protected]>
SummaryFixes interface implementation methods being incorrectly converted to async by the migration code fixer. Critical IssuesNone found ✅ Suggestions1. Potential Performance Concern - HashSet allocationThe CollectInterfaceImplementingMethods method is called during code fix application. While this is not as hot as test discovery/execution, it still allocates a new HashSet and iterates through all methods. Location: TUnit.Analyzers.CodeFixers/Base/AsyncMethodSignatureRewriter.cs:19-66 Consider:
2. Method Key StabilityThe GetMethodKey method uses string concatenation to create method signatures. The key format should remain stable across syntax tree modifications (before/after conversion), which appears to be the case. Location: TUnit.Analyzers.CodeFixers/Base/AsyncMethodSignatureRewriter.cs:83-91 3. Test CoverageThe added test covers the implicit interface implementation case well. Consider adding edge cases for explicit interface implementations, generic interfaces, and multiple interface implementations, though the explicit case is already handled by checking ExplicitInterfaceSpecifier. Technical Review✅ Dual-mode: N/A - This is analyzer/code fixer code, not engine metadata collection The two-pass approach (collect interface implementations before modifications, then check during rewriting) is the correct solution since the semantic model becomes invalid after syntax tree modifications. Verdict✅ APPROVE - Well-implemented fix with appropriate test coverage. The solution correctly handles the semantic model invalidation problem and prevents breaking interface implementation contracts. |
Summary
Methods that implement interface members should NOT have their signatures converted to
async Taskbecause this would break the interface implementation contract.The fix uses a two-pass approach:
Also adds
ref/out/inparameter check to prevent async conversion of methods with those parameter types (which cannot be async).Changes
AsyncMethodSignatureRewriterto accept a set of interface-implementing method keysCollectInterfaceImplementingMethodsthat uses semantic analysis to identify interface implementationsBaseMigrationCodeFixProviderto collect interface-implementing methods before modificationsTest plan
Fixes #4342
🤖 Generated with Claude Code