Skip to content

Commit 3dce56b

Browse files
authored
Merge pull request #17276 from tamasvajk/impr/change-partial-method-location
C#: Change reporting location of partial methods
2 parents a1688f6 + f7bf5e8 commit 3dce56b

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Entities/OrdinaryMethod.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected OrdinaryMethod(Context cx, IMethodSymbol init)
2121
public override Microsoft.CodeAnalysis.Location ReportingLocation =>
2222
IsCompilerGeneratedDelegate()
2323
? Symbol.ContainingType.GetSymbolLocation()
24-
: Symbol.GetSymbolLocation();
24+
: BodyDeclaringSymbol.GetSymbolLocation();
2525

2626
public override bool NeedsPopulation => base.NeedsPopulation || IsCompilerGeneratedDelegate();
2727

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The reported location of `partial` methods has been changed from the definition to the implementation part.

csharp/ql/test/library-tests/partial/MethodIsPartial.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
| Partial.cs:3:18:3:39 | PartialMethodWithBody1 | true |
21
| Partial.cs:4:18:4:42 | PartialMethodWithoutBody1 | true |
32
| Partial.cs:5:17:5:23 | Method2 | false |
3+
| Partial.cs:10:18:10:39 | PartialMethodWithBody1 | true |
44
| Partial.cs:11:17:11:23 | Method3 | false |
55
| Partial.cs:16:18:16:42 | PartialMethodWithoutBody2 | true |
66
| Partial.cs:17:17:17:23 | Method4 | false |
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
| Partial.cs:1:15:1:26 | TwoPartClass |
2-
| Partial.cs:3:18:3:39 | PartialMethodWithBody1 |
32
| Partial.cs:4:18:4:42 | PartialMethodWithoutBody1 |
43
| Partial.cs:8:15:8:26 | TwoPartClass |
4+
| Partial.cs:10:18:10:39 | PartialMethodWithBody1 |
55
| Partial.cs:14:15:14:33 | OnePartPartialClass |
66
| Partial.cs:16:18:16:42 | PartialMethodWithoutBody2 |
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
| Partial.cs:1:15:1:26 | TwoPartClass | Partial.cs:3:18:3:39 | PartialMethodWithBody1 |
21
| Partial.cs:1:15:1:26 | TwoPartClass | Partial.cs:4:18:4:42 | PartialMethodWithoutBody1 |
32
| Partial.cs:1:15:1:26 | TwoPartClass | Partial.cs:5:17:5:23 | Method2 |
3+
| Partial.cs:1:15:1:26 | TwoPartClass | Partial.cs:10:18:10:39 | PartialMethodWithBody1 |
44
| Partial.cs:1:15:1:26 | TwoPartClass | Partial.cs:11:17:11:23 | Method3 |
5-
| Partial.cs:8:15:8:26 | TwoPartClass | Partial.cs:3:18:3:39 | PartialMethodWithBody1 |
65
| Partial.cs:8:15:8:26 | TwoPartClass | Partial.cs:4:18:4:42 | PartialMethodWithoutBody1 |
76
| Partial.cs:8:15:8:26 | TwoPartClass | Partial.cs:5:17:5:23 | Method2 |
7+
| Partial.cs:8:15:8:26 | TwoPartClass | Partial.cs:10:18:10:39 | PartialMethodWithBody1 |
88
| Partial.cs:8:15:8:26 | TwoPartClass | Partial.cs:11:17:11:23 | Method3 |
99
| Partial.cs:14:15:14:33 | OnePartPartialClass | Partial.cs:16:18:16:42 | PartialMethodWithoutBody2 |
1010
| Partial.cs:14:15:14:33 | OnePartPartialClass | Partial.cs:17:17:17:23 | Method4 |
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| Partial.cs:3:18:3:39 | PartialMethodWithBody1 | true |
21
| Partial.cs:4:18:4:42 | PartialMethodWithoutBody1 | false |
2+
| Partial.cs:10:18:10:39 | PartialMethodWithBody1 | true |
33
| Partial.cs:16:18:16:42 | PartialMethodWithoutBody2 | false |

csharp/ql/test/library-tests/partial/PrintAst.expected

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
Partial.cs:
22
# 1| [Class] TwoPartClass
3-
# 3| 5: [Method] PartialMethodWithBody1
4-
# 3| -1: [TypeMention] Void
5-
# 10| 4: [BlockStmt] {...}
6-
# 4| 6: [Method] PartialMethodWithoutBody1
3+
# 4| 5: [Method] PartialMethodWithoutBody1
74
# 4| -1: [TypeMention] Void
8-
# 5| 7: [Method] Method2
5+
# 5| 6: [Method] Method2
96
# 5| -1: [TypeMention] Void
107
# 5| 4: [BlockStmt] {...}
8+
# 10| 7: [Method] PartialMethodWithBody1
9+
# 3| -1: [TypeMention] Void
10+
# 10| 4: [BlockStmt] {...}
1111
# 11| 8: [Method] Method3
1212
# 11| -1: [TypeMention] Void
1313
# 11| 4: [BlockStmt] {...}

0 commit comments

Comments
 (0)