Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions csharp/ql/lib/qlpack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ dataExtensions:
- ext/*.model.yml
- ext/generated/*.model.yml
warnOnImplicitThis: true
compileForOverlayEval: true
15 changes: 10 additions & 5 deletions csharp/ql/lib/semmle/code/csharp/Conversion.qll
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,15 @@ private Type convTypeParameterBase(TypeParameter tp) {
result = getATypeParameterFromConstraints+(tp)
}

pragma[noinline]
private Class typeConstraintToBaseType(TypeParameterConstraints tpc) {
tpc.hasValueTypeConstraint() and result instanceof SystemValueTypeClass
or
result = tpc.getATypeConstraint()
or
tpc.hasRefTypeConstraint() and result instanceof ObjectType
}

/**
* 10.1.5: Candidates for the effective base class of type parameter `tp`.
*
Expand All @@ -731,13 +740,9 @@ private Class effectiveBaseClassCandidate(TypeParameter tp) {
not hasPrimaryConstraints(tp) and result instanceof ObjectType
or
exists(TypeParameterConstraints tpc | tpc = tp.getConstraints() |
tpc.hasValueTypeConstraint() and result instanceof SystemValueTypeClass
or
result = tpc.getATypeConstraint()
result = typeConstraintToBaseType(tpc)
or
result = effectiveBaseClassCandidate(tpc.getATypeConstraint())
or
tpc.hasRefTypeConstraint() and result instanceof ObjectType
)
}

Expand Down