Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8cbdd30

Browse files
committed
Fix generic type constraint stubbing on overrides
1 parent ff4db5b commit 8cbdd30

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,22 @@ private string stubConstraints(TypeParameterConstraints tpc) {
433433
}
434434

435435
private string stubTypeParameterConstraints(TypeParameter tp) {
436-
exists(TypeParameterConstraints tpc | tpc = tp.getConstraints() |
437-
result =
438-
" where " + tp.getName() + ": " + strictconcat(string s | s = stubConstraints(tpc) | s, ", ")
439-
)
436+
if
437+
tp.getDeclaringGeneric().(Virtualizable).isOverride() or
438+
tp.getDeclaringGeneric().(Virtualizable).implementsExplicitInterface()
439+
then
440+
if tp.getConstraints().hasValueTypeConstraint()
441+
then result = " where " + tp.getName() + ": struct"
442+
else
443+
if tp.getConstraints().hasRefTypeConstraint()
444+
then result = " where " + tp.getName() + ": class"
445+
else result = ""
446+
else
447+
exists(TypeParameterConstraints tpc | tpc = tp.getConstraints() |
448+
result =
449+
" where " + tp.getName() + ": " +
450+
strictconcat(string s | s = stubConstraints(tpc) | s, ", ")
451+
)
440452
}
441453

442454
private string stubTypeParametersConstraints(Declaration d) {

0 commit comments

Comments
 (0)