C#: Extract correct method symbol as target of extension method calls

This commit is contained in:
Tamas Vajk
2021-06-01 13:01:44 +02:00
parent fc0fc740ac
commit e05e2365ea
3 changed files with 10 additions and 7 deletions

View File

@@ -272,6 +272,10 @@ namespace Semmle.Extraction.CSharp.Entities
case MethodKind.Constructor:
return Constructor.Create(cx, methodDecl);
case MethodKind.ReducedExtension:
return OrdinaryMethod.Create(cx,
methodDecl.ReducedFrom!.IsGenericMethod && methodDecl.TypeArguments.Any()
? methodDecl.ReducedFrom!.Construct(methodDecl.TypeArguments, methodDecl.TypeArgumentNullableAnnotations)
: methodDecl.ReducedFrom!);
case MethodKind.Ordinary:
case MethodKind.DelegateInvoke:
return OrdinaryMethod.Create(cx, methodDecl);

View File

@@ -1,8 +1,8 @@
methodCallTargets
| methods.cs:19:13:19:22 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
| methods.cs:20:13:20:27 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
| methods.cs:21:13:21:30 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(double) |
| methods.cs:22:13:22:33 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<object>(object) |
| methods.cs:21:13:21:30 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<double>(string, double) |
| methods.cs:22:13:22:33 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<object>(string, object) |
| methods.cs:23:13:23:34 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
| methods.cs:24:13:24:39 | call to method Ext0 | methods.cs:8:28:8:34 | Ext0 | Ext0<int>(string, int) |
| 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
genericMethodCallTargets
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |
| 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) |

View File

@@ -16,11 +16,10 @@
| methods.cs:73:21:73:24 | F | methods.cs:73:28:73:28 | x |
| methods.cs:78:21:78:21 | F | methods.cs:78:30:78:30 | x |
| methods.cs:78:21:78:21 | F | methods.cs:78:40:78:40 | y |
| methods.cs:100:27:100:33 | ToInt32 | methods.cs:100:35:100:47 | s |
| methods.cs:100:27:100:33 | ToInt32 | methods.cs:100:47:100:47 | s |
| methods.cs:105:28:105:33 | ToBool | methods.cs:105:47:105:47 | s |
| methods.cs:105:28:105:33 | ToBool | methods.cs:105:69:105:69 | f |
| methods.cs:110:27:110:34 | Slice | methods.cs:110:36:110:50 | source |
| methods.cs:110:27:110:34 | Slice | methods.cs:110:45:110:50 | source |
| methods.cs:110:27:110:34 | Slice | methods.cs:110:45:110:50 | source |
| methods.cs:110:27:110:34 | Slice | methods.cs:110:57:110:61 | index |
| methods.cs:110:27:110:34 | Slice | methods.cs:110:57:110:61 | index |
@@ -35,7 +34,7 @@
| methods.cs:146:14:146:20 | Method2 | methods.cs:146:65:146:65 | e |
| methods.cs:169:27:169:30 | Plus | methods.cs:169:41:169:44 | left |
| methods.cs:169:27:169:30 | Plus | methods.cs:169:51:169:55 | right |
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:76:174:126 | list |
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:123:174:126 | list |
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:123:174:126 | list |
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:133:174:133 | i |
| methods.cs:174:65:174:74 | SkipTwo | methods.cs:174:133:174:133 | i |