Skip to content

Commit 92d9aa3

Browse files
CopilotEvangelinkCopilot
authored
Avoid false duplicate-code reports for required AOT attributes (#11749)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Amaury Levé <amauryleve@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent c884c41 commit 92d9aa3

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎.github/workflows/duplicate-code-detector.lock.yml‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.github/workflows/duplicate-code-detector.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,16 @@ Assess findings to identify true code duplication:
121121
- **Impact**: Where duplication occurs (critical paths, frequently called code)
122122
- **Maintainability**: How duplication affects code maintainability
123123
- **Refactoring Opportunity**: Whether duplication can be easily refactored
124+
- **Semantic Equivalence**: Verify that a proposed extraction preserves compiler, analyzer, linker, and runtime behavior
125+
- **Existing Safeguards**: Search tests for guards that already keep intentionally repeated declarations synchronized
124126

125127
### 4. Issue Reporting
126128

127129
Create separate issues for each distinct duplication pattern found (maximum 3 patterns per run). Each pattern should get its own issue to enable focused remediation.
128130

129131
**When to Create Issues**:
130132
- Only create issues if significant duplication is found (threshold: >10 lines of duplicated code OR 3+ instances of similar patterns)
133+
- Require at least one concrete, behavior-preserving refactoring approach; use `noop` when language or tooling semantics require the repetition
131134
- **Create one issue per distinct duplication pattern** - do NOT bundle multiple patterns in a single issue
132135
- Limit to the top 3 most significant patterns if more are found
133136
- Use the `create_issue` tool from safe-outputs MCP **once for each pattern**
@@ -158,6 +161,7 @@ Create separate issues for each distinct duplication pattern found (maximum 3 pa
158161
- **All workflow files** (files under `.github/workflows/*`)
159162
- Configuration files with similar structure
160163
- Language-specific patterns (constructors, getters/setters)
164+
- Declaration-site attributes, annotations, or modifiers that compilers, analyzers, linkers, or runtimes require on every affected member. In particular, do not suggest wrapping built-in trimming or AOT attributes in a custom attribute when that would stop caller diagnostics.
161165
- Small code snippets (<5 lines) unless highly repetitive
162166
- Generated code or vendored dependencies
163167

‎src/TestFramework/TestFramework/Assertions/Assert.AreEquivalent.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting;
55

66
public sealed partial class Assert
77
{
8+
// Trimming and AOT diagnostics require the framework attributes to be applied directly to every public
9+
// overload. StructuralEquivalenceAssertions_DeclareTrimAndAotRequirements keeps the repeated declarations
10+
// synchronized.
811
#if NET5_0_OR_GREATER
912
private const string EquivalenceRequiresUnreferencedCodeMessage = "Structural comparison uses reflection over runtime types, whose members cannot be statically preserved.";
1013
#endif

0 commit comments

Comments
 (0)