CodeQL library for C#
codeql/csharp-all 0.9.1 (changelog, source)
Search

Predicate Unification::unifiable

Holds if types t1 and t2 are unifiable. That is, it is possible to replace all type parameters in t1 and t2 with some (other) types to make the two substituted terms equal.

This predicate covers only the case when t1 and t2 are constructed types; the other three cases are:

  1. Neither t1 nor t2 are type parameters; in this case t1 and t2 must be equal.
  2. t1 or t2 is an unconstrained type parameter; in this case t1 and t2 are always unifiable.
  3. t1 or t2 is a constrained type parameter; in this case the predicate ConstrainedTypeParameter::unifiable() can be used.

For performance reasons, type parameter constraints inside t1 and t2 are not taken into account, and there is also no guarantee that the same type parameter can be substituted with two different terms. For example, in

class C<T1, T2>
{
    void M<T3>(C<T3, T3> c) where T3 : struct { }
}

the type C<T3, T3> is considered unifiable with both C<object, object> and C<int, bool>.

Note: This predicate is inlined.

Import path

import semmle.code.csharp.Unification
predicate unifiable(Type t1, Type t2)