Skip to content

Commit 7611bfb

Browse files
committed
C#: Apply closed-world assumption for type-parameter qualifiers in dynamic calls
1 parent 1da885f commit 7611bfb

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

csharp/ql/lib/semmle/code/csharp/Unification.qll

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,23 +538,26 @@ module Unification {
538538
*
539539
* Note: This predicate is inlined.
540540
*/
541-
bindingset[t]
541+
bindingset[this]
542+
pragma[inline_late]
542543
predicate unifiable(Type t) { none() }
543544

544545
/**
545546
* Holds if this type parameter subsumes type `t`
546547
*
547548
* Note: This predicate is inlined.
548549
*/
549-
bindingset[t]
550+
bindingset[this]
551+
pragma[inline_late]
550552
predicate subsumes(Type t) { none() }
551553
}
552554

553555
/** A type parameter that has a single constraint. */
554556
private class SingleConstraintTypeParameter extends ConstrainedTypeParameter {
555557
SingleConstraintTypeParameter() { constraintCount = 1 }
556558

557-
bindingset[t]
559+
bindingset[this]
560+
pragma[inline_late]
558561
override predicate unifiable(Type t) {
559562
exists(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
560563
ttc = TRefTypeConstraint() and
@@ -567,7 +570,8 @@ module Unification {
567570
)
568571
}
569572

570-
bindingset[t]
573+
bindingset[this]
574+
pragma[inline_late]
571575
override predicate subsumes(Type t) {
572576
exists(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
573577
ttc = TRefTypeConstraint() and
@@ -585,9 +589,13 @@ module Unification {
585589
private class MultiConstraintTypeParameter extends ConstrainedTypeParameter {
586590
MultiConstraintTypeParameter() { constraintCount > 1 }
587591

588-
bindingset[t]
592+
pragma[nomagic]
593+
TTypeParameterConstraint getATypeConstraint() { result = getATypeConstraint(this) }
594+
595+
bindingset[this]
596+
pragma[inline_late]
589597
override predicate unifiable(Type t) {
590-
forex(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
598+
forex(TTypeParameterConstraint ttc | ttc = this.getATypeConstraint() |
591599
ttc = TRefTypeConstraint() and
592600
t.isRefType()
593601
or
@@ -598,9 +606,10 @@ module Unification {
598606
)
599607
}
600608

601-
bindingset[t]
609+
bindingset[this]
610+
pragma[inline_late]
602611
override predicate subsumes(Type t) {
603-
forex(TTypeParameterConstraint ttc | ttc = getATypeConstraint(this) |
612+
forex(TTypeParameterConstraint ttc | ttc = this.getATypeConstraint() |
604613
ttc = TRefTypeConstraint() and
605614
t.isRefType()
606615
or

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -862,9 +862,7 @@ private module Internal {
862862
or
863863
Unification::subsumes(t, qualifierType)
864864
or
865-
t.(Unification::ConstrainedTypeParameter).unifiable(qualifierType)
866-
or
867-
qualifierType = t.(Unification::UnconstrainedTypeParameter).getAnUltimatelySuppliedType()
865+
qualifierType = t.(TypeParameter).getAnUltimatelySuppliedType()
868866
)
869867
}
870868

0 commit comments

Comments
 (0)