@@ -1092,7 +1092,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1092
1092
* For example, if this access is the method call `M(42)`, then the inferred
1093
1093
* type at argument position `0` is `int`.
1094
1094
*/
1095
- bindingset [ state]
1096
1095
Type getInferredType ( State state , AccessPosition apos , TypePath path ) ;
1097
1096
1098
1097
/** Gets the declaration that this access targets in `state`. */
@@ -1103,29 +1102,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1103
1102
bindingset [ apos]
1104
1103
bindingset [ dpos]
1105
1104
predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) ;
1106
-
1107
- /**
1108
- * Holds if matching an inferred type `t` at `path` inside an access at `apos`
1109
- * against the declaration `target` means that the type should be adjusted to
1110
- * `tAdj` at `pathAdj`.
1111
- *
1112
- * For example, in
1113
- *
1114
- * ```csharp
1115
- * void M(int? i) {}
1116
- * M(42);
1117
- * ```
1118
- *
1119
- * the inferred type of `42` is `int`, but it should be adjusted to `int?`
1120
- * when matching against `M`.
1121
- */
1122
- bindingset [ apos, target, path, t]
1123
- default predicate adjustAccessType (
1124
- AccessPosition apos , Declaration target , TypePath path , Type t , TypePath pathAdj , Type tAdj
1125
- ) {
1126
- pathAdj = path and
1127
- tAdj = t
1128
- }
1129
1105
}
1130
1106
1131
1107
/**
@@ -1137,21 +1113,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1137
1113
module MatchingWithState< MatchingWithStateInputSig Input> {
1138
1114
private import Input
1139
1115
1140
- /**
1141
- * Holds if `a` targets `target` in `state` and the type for `apos` at `path`
1142
- * in `a` is `t` after adjustment by `target`.
1143
- */
1144
- pragma [ nomagic]
1145
- private predicate adjustedAccessType (
1146
- Access a , State state , AccessPosition apos , Declaration target , TypePath path , Type t
1147
- ) {
1148
- target = a .getTarget ( state ) and
1149
- exists ( TypePath path0 , Type t0 |
1150
- t0 = a .getInferredType ( state , apos , path0 ) and
1151
- adjustAccessType ( apos , target , path0 , t0 , path , t )
1152
- )
1153
- }
1154
-
1155
1116
/**
1156
1117
* Gets the type of the type argument at `path` in `a` that corresponds to
1157
1118
* the type parameter `tp` in `target`, if any.
@@ -1182,7 +1143,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1182
1143
exists ( AccessPosition apos , DeclarationPosition dpos , TypePath pathToTypeParam |
1183
1144
tp = target .getDeclaredType ( dpos , pathToTypeParam ) and
1184
1145
accessDeclarationPositionMatch ( apos , dpos ) and
1185
- adjustedAccessType ( a , state , apos , target , pathToTypeParam .appendInverse ( path ) , t )
1146
+ target = a .getTarget ( state ) and
1147
+ t = a .getInferredType ( state , apos , pathToTypeParam .appendInverse ( path ) )
1186
1148
)
1187
1149
}
1188
1150
@@ -1193,7 +1155,7 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1193
1155
*/
1194
1156
private predicate relevantAccess ( Access a , State state , AccessPosition apos , Type base ) {
1195
1157
exists ( Declaration target , DeclarationPosition dpos |
1196
- adjustedAccessType ( a , state , apos , target , _ , _ ) and
1158
+ target = a . getTarget ( state ) and
1197
1159
accessDeclarationPositionMatch ( apos , dpos ) and
1198
1160
declarationBaseType ( target , dpos , base , _, _)
1199
1161
)
@@ -1268,10 +1230,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1268
1230
}
1269
1231
1270
1232
private newtype TRelevantAccess =
1271
- MkRelevantAccess (
1272
- Access a , State state , Declaration target , AccessPosition apos , TypePath path
1273
- ) {
1274
- relevantAccessConstraint ( a , state , target , apos , path , _)
1233
+ MkRelevantAccess ( Access a , State state , AccessPosition apos , TypePath path ) {
1234
+ relevantAccessConstraint ( a , state , _, apos , path , _)
1275
1235
}
1276
1236
1277
1237
/**
@@ -1281,18 +1241,19 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1281
1241
private class RelevantAccess extends MkRelevantAccess {
1282
1242
Access a ;
1283
1243
State state ;
1284
- Declaration target ;
1285
1244
AccessPosition apos ;
1286
1245
TypePath path ;
1287
1246
1288
- RelevantAccess ( ) { this = MkRelevantAccess ( a , state , target , apos , path ) }
1247
+ RelevantAccess ( ) { this = MkRelevantAccess ( a , state , apos , path ) }
1289
1248
1290
1249
Type getTypeAt ( TypePath suffix ) {
1291
- adjustedAccessType ( a , state , apos , target , path .appendInverse ( suffix ) , result )
1250
+ result = a . getInferredType ( state , apos , path .appendInverse ( suffix ) )
1292
1251
}
1293
1252
1294
1253
/** Holds if this relevant access should satisfy `constraint`. */
1295
- Type getConstraint ( ) { relevantAccessConstraint ( a , state , target , apos , path , result ) }
1254
+ Type getConstraint ( Declaration target ) {
1255
+ relevantAccessConstraint ( a , state , target , apos , path , result )
1256
+ }
1296
1257
1297
1258
string toString ( ) {
1298
1259
result = a .toString ( ) + ", " + apos .toString ( ) + ", " + path .toString ( )
@@ -1305,16 +1266,20 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1305
1266
SatisfiesConstraintInputSig< RelevantAccess >
1306
1267
{
1307
1268
predicate relevantConstraint ( RelevantAccess at , Type constraint ) {
1308
- constraint = at .getConstraint ( )
1269
+ constraint = at .getConstraint ( _ )
1309
1270
}
1310
1271
}
1311
1272
1312
1273
predicate satisfiesConstraintType (
1313
1274
Access a , State state , Declaration target , AccessPosition apos , TypePath prefix ,
1314
1275
Type constraint , TypePath path , Type t
1315
1276
) {
1316
- SatisfiesConstraint< RelevantAccess , SatisfiesConstraintInput > :: satisfiesConstraintType ( MkRelevantAccess ( a ,
1317
- state , target , apos , prefix ) , constraint , path , t )
1277
+ exists ( RelevantAccess ra |
1278
+ ra = MkRelevantAccess ( a , state , apos , prefix ) and
1279
+ SatisfiesConstraint< RelevantAccess , SatisfiesConstraintInput > :: satisfiesConstraintType ( ra ,
1280
+ constraint , path , t ) and
1281
+ constraint = ra .getConstraint ( target )
1282
+ )
1318
1283
}
1319
1284
}
1320
1285
@@ -1605,29 +1570,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1605
1570
bindingset [ apos]
1606
1571
bindingset [ dpos]
1607
1572
predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) ;
1608
-
1609
- /**
1610
- * Holds if matching an inferred type `t` at `path` inside an access at `apos`
1611
- * against the declaration `target` means that the type should be adjusted to
1612
- * `tAdj` at `pathAdj`.
1613
- *
1614
- * For example, in
1615
- *
1616
- * ```csharp
1617
- * void M(int? i) {}
1618
- * M(42);
1619
- * ```
1620
- *
1621
- * the inferred type of `42` is `int`, but it should be adjusted to `int?`
1622
- * when matching against `M`.
1623
- */
1624
- bindingset [ apos, target, path, t]
1625
- default predicate adjustAccessType (
1626
- AccessPosition apos , Declaration target , TypePath path , Type t , TypePath pathAdj , Type tAdj
1627
- ) {
1628
- pathAdj = path and
1629
- tAdj = t
1630
- }
1631
1573
}
1632
1574
1633
1575
/**
@@ -1641,8 +1583,6 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1641
1583
private import codeql.util.Unit
1642
1584
import Input
1643
1585
1644
- predicate adjustAccessType = Input:: adjustAccessType / 6 ;
1645
-
1646
1586
class State = Unit ;
1647
1587
1648
1588
final private class AccessFinal = Input:: Access ;
0 commit comments