Skip to content

Commit ef5ae3f

Browse files
committed
C#: Add some unification and viable callable test cases.
1 parent b9fce5e commit ef5ae3f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,3 +588,33 @@ void Run<T>(T c) where T : I3<T>
588588
c.M13();
589589
}
590590
}
591+
592+
public class C21
593+
{
594+
public interface I
595+
{
596+
void M();
597+
}
598+
599+
public class A1 : I
600+
{
601+
public void M() { }
602+
}
603+
604+
public ref struct A2 : I
605+
{
606+
public void M() { }
607+
}
608+
609+
public void Run1<T>(T t) where T : I
610+
{
611+
// Viable callable: A1.M() [also reports A2.M(); false positive]
612+
t.M();
613+
}
614+
615+
public void Run2<T>(T t) where T : I, allows ref struct
616+
{
617+
// Viable callable: {A1, A2}.M()
618+
t.M();
619+
}
620+
}

csharp/ql/test/library-tests/unification/Unification.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ public class NestedC<T12> { }
4848
Nested<int>.NestedB.NestedC<bool> x5;
4949
Nested<string>.NestedB.NestedC<decimal> x6;
5050
}
51+
52+
interface I2 { }
53+
struct S3 : I2 { }
54+
ref struct RS : I2 { }
55+
class C7 : I2 { }
56+
57+
class NormalConstraint<T> where T : I2 { } // False positive: Allows T to be `RS`.
58+
class NegativeConstraint<T> where T : I2, allows ref struct { }

0 commit comments

Comments
 (0)