Skip to content

Commit 3df3054

Browse files
authored
Merge pull request #7628 from michaelnebel/csharp/issue-7609
C#: Fix false positive alert for shadowing on record types.
2 parents bdfde88 + edafdc8 commit 3df3054

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `cs/local-shadows-member` no longer highlights parameters of `record` types.

csharp/ql/src/Bad Practices/Declarations/LocalScopeVariableShadowsMember.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ private predicate acceptableShadowing(LocalScopeVariable v, Member m) {
3939
)
4040
or
4141
t.getAConstructor().getAParameter() = v
42+
or
43+
// Record types have auto-generated Deconstruct methods, which declare an out parameter
44+
// with the same name as the property field(s).
45+
t.(RecordType).getAMethod("Deconstruct").getAParameter() = v
4246
)
4347
}
4448

csharp/ql/test/query-tests/Bad Practices/Declarations/LocalScopeVariableShadowsMember/LocalScopeVariableShadowsMember.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ class C4 : C
6161
{
6262
public C4(int f) { } // GOOD
6363
}
64+
65+
record class GoodRecordClass(object Prop1, object Prop2) { } // GOOD
66+
67+
record struct GoodRecordStruct(object Prop1, object Prop2) { } // GOOD
6468
}

0 commit comments

Comments
 (0)