Skip to content

Commit ad04099

Browse files
authored
Merge pull request github#6630 from tamasvajk/feature/interface-runtimecallable
C# Extend runtime callables to cover interface members with default implementation
2 parents 4c74709 + 9ab6c29 commit ad04099

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

csharp/ql/lib/semmle/code/csharp/dispatch/RuntimeCallable.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ private import dotnet
1515
class RuntimeCallable extends DotNet::Callable {
1616
RuntimeCallable() {
1717
not this.(Modifiable).isAbstract() and
18-
not getDeclaringType() instanceof Interface
18+
(
19+
not getDeclaringType() instanceof Interface or
20+
this.(Virtualizable).isVirtual()
21+
)
1922
}
2023
}
2124

csharp/ql/test/library-tests/dispatch/CallGraph.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,5 @@
236236
| ViableCallable.cs:452:10:452:14 | M4<> | ViableCallable.cs:444:23:444:27 | M2<> |
237237
| ViableCallable.cs:458:10:458:14 | M5<> | ViableCallable.cs:430:22:430:26 | M2<> |
238238
| ViableCallable.cs:458:10:458:14 | M5<> | ViableCallable.cs:444:23:444:27 | M2<> |
239+
| ViableCallable.cs:475:10:475:12 | Run | ViableCallable.cs:468:10:468:11 | M2 |
240+
| ViableCallable.cs:475:10:475:12 | Run | ViableCallable.cs:473:17:473:18 | M1 |

csharp/ql/test/library-tests/dispatch/GetADynamicTarget.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,5 @@
469469
| ViableCallable.cs:455:9:455:30 | call to method M2<T> | C17.M2<T>(Func<T>) |
470470
| ViableCallable.cs:461:9:461:30 | call to method M2<T> | C16<T,System.Int32>.M2<T>(Func<T>) |
471471
| ViableCallable.cs:461:9:461:30 | call to method M2<T> | C17.M2<T>(Func<T>) |
472+
| ViableCallable.cs:478:9:478:14 | call to method M1 | C18.M1() |
473+
| ViableCallable.cs:481:9:481:14 | call to method M2 | I2.M2() |

csharp/ql/test/library-tests/dispatch/ViableCallable.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,3 +461,23 @@ void M5<T>(C16<T, int> c) where T : class
461461
c.M2(() => default(T));
462462
}
463463
}
464+
465+
interface I2
466+
{
467+
void M1();
468+
void M2() => throw null;
469+
}
470+
471+
class C18 : I2
472+
{
473+
public void M1() { }
474+
475+
void Run(I2 i)
476+
{
477+
// Viable callables: C18.M1()
478+
i.M1();
479+
480+
// Viable callables: I2.M2()
481+
i.M2();
482+
}
483+
}

csharp/ql/test/library-tests/dispatch/viableCallable.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,5 @@
251251
| ViableCallable.cs:419:9:419:21 | call to method M<String> | M<> | A4 |
252252
| ViableCallable.cs:423:9:423:21 | call to method M<String> | M<> | A4 |
253253
| ViableCallable.cs:423:9:423:21 | call to method M<String> | M<> | A5 |
254+
| ViableCallable.cs:478:9:478:14 | call to method M1 | M1 | C18 |
255+
| ViableCallable.cs:481:9:481:14 | call to method M2 | M2 | I2 |

0 commit comments

Comments
 (0)