Skip to content

Commit e05e236

Browse files
committed
C#: Extract correct method symbol as target of extension method calls
1 parent fc0fc74 commit e05e236

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ public static void AddExplicitInterfaceQualifierToId(Context cx, EscapingTextWri
272272
case MethodKind.Constructor:
273273
return Constructor.Create(cx, methodDecl);
274274
case MethodKind.ReducedExtension:
275+
return OrdinaryMethod.Create(cx,
276+
methodDecl.ReducedFrom!.IsGenericMethod && methodDecl.TypeArguments.Any()
277+
? methodDecl.ReducedFrom!.Construct(methodDecl.TypeArguments, methodDecl.TypeArgumentNullableAnnotations)
278+
: methodDecl.ReducedFrom!);
275279
case MethodKind.Ordinary:
276280
case MethodKind.DelegateInvoke:
277281
return OrdinaryMethod.Create(cx, methodDecl);

csharp/ql/test/library-tests/extension-method-call/ExtensionMethodCalls.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
methodCallTargets
22
| methods.cs:19:13:19:22 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
33
| methods.cs:20:13:20:27 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
4-
| methods.cs:21:13:21:30 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(double) |
5-
| methods.cs:22:13:22:33 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<object>(object) |
4+
| methods.cs:21:13:21:30 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(string, double) |
5+
| methods.cs:22:13:22:33 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<object>(string, object) |
66
| methods.cs:23:13:23:34 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
77
| methods.cs:24:13:24:39 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
88
| methods.cs:25:13:25:42 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(string, double) |
@@ -22,8 +22,8 @@ methodCallTargets
2222
genericMethodCallTargets
2323
| methods.cs:19:13:19:22 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
2424
| methods.cs:20:13:20:27 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
25-
| methods.cs:21:13:21:30 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(double) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
26-
| methods.cs:22:13:22:33 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<object>(object) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
25+
| methods.cs:21:13:21:30 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(string, double) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
26+
| methods.cs:22:13:22:33 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<object>(string, object) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
2727
| methods.cs:23:13:23:34 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
2828
| methods.cs:24:13:24:39 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |
2929
| methods.cs:25:13:25:42 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(string, double) | methods.cs:8:28:8:34 | Ext0 | Ext0<T>(string, T) |

csharp/ql/test/library-tests/methods/Parameters8.expected

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
| methods.cs:73:21:73:24 | F | methods.cs:73:28:73:28 | x |
1717
| methods.cs:78:21:78:21 | F | methods.cs:78:30:78:30 | x |
1818
| methods.cs:78:21:78:21 | F | methods.cs:78:40:78:40 | y |
19-
| methods.cs:100:27:100:33 | ToInt32 | methods.cs:100:35:100:47 | s |
2019
| methods.cs:100:27:100:33 | ToInt32 | methods.cs:100:47:100:47 | s |
2120
| methods.cs:105:28:105:33 | ToBool | methods.cs:105:47:105:47 | s |
2221
| methods.cs:105:28:105:33 | ToBool | methods.cs:105:69:105:69 | f |
23-
| methods.cs:110:27:110:34 | Slice | methods.cs:110:36:110:50 | source |
22+
| methods.cs:110:27:110:34 | Slice | methods.cs:110:45:110:50 | source |
2423
| methods.cs:110:27:110:34 | Slice | methods.cs:110:45:110:50 | source |
2524
| methods.cs:110:27:110:34 | Slice | methods.cs:110:57:110:61 | index |
2625
| methods.cs:110:27:110:34 | Slice | methods.cs:110:57:110:61 | index |
@@ -35,7 +34,7 @@
3534
| methods.cs:146:14:146:20 | Method2 | methods.cs:146:65:146:65 | e |
3635
| methods.cs:169:27:169:30 | Plus | methods.cs:169:41:169:44 | left |
3736
| methods.cs:169:27:169:30 | Plus | methods.cs:169:51:169:55 | right |
38-
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:76:174:126 | list |
37+
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:123:174:126 | list |
3938
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:123:174:126 | list |
4039
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:133:174:133 | i |
4140
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:133:174:133 | i |

0 commit comments

Comments
 (0)