@@ -1283,8 +1283,9 @@ private Type testinferCallExprBaseType(
1283
1283
CallExprBaseMatchingInput:: Access a , string state , CallExprBaseMatchingInput:: AccessPosition apos ,
1284
1284
TypePath path
1285
1285
) {
1286
- a .getLocation ( ) .getStartLine ( ) = 73 and
1287
- a .fromSource ( ) and
1286
+ // a.getLocation().getStartLine() = 73 and
1287
+ // a.fromSource() and
1288
+ a = Debug:: getRelevantLocatable ( ) and
1288
1289
result = CallExprBaseMatching:: inferAccessType ( a , state , apos , path )
1289
1290
}
1290
1291
@@ -2068,11 +2069,16 @@ final class MethodCall extends Call {
2068
2069
2069
2070
pragma [ nomagic]
2070
2071
private predicate isMethodCall0 ( Type rootType , string name , int arity , string derefChain ) {
2071
- rootType = this .getACandidateReceiverTypeAt ( TypePath:: nil ( ) , derefChain ) and //, mcd.getTypeAt(TypePath::singleton(TRefTypeParameter()))] and
2072
+ rootType = this .getACandidateReceiverTypeRefsAt ( TypePath:: nil ( ) , derefChain ) and //, mcd.getTypeAt(TypePath::singleton(TRefTypeParameter()))] and
2072
2073
name = this .getMethodName ( ) and
2073
2074
arity = this .getNumberOfArguments ( )
2074
2075
}
2075
2076
2077
+ private predicate testisMethodCall0 ( Type rootType , string name , int arity , string derefChain ) {
2078
+ this .isMethodCall0 ( rootType , name , arity , derefChain ) and
2079
+ this = Debug:: getRelevantLocatable ( )
2080
+ }
2081
+
2076
2082
/**
2077
2083
* Gets a [candidate receiver type][1] of this method call.
2078
2084
*
@@ -2124,7 +2130,7 @@ final class MethodCall extends Call {
2124
2130
this .receiverImplicitlyBorrowed ( ) and
2125
2131
result = this .getACandidateReceiverTypeAt ( path , derefChain ) and
2126
2132
exists ( Type rootType , string name , int arity |
2127
- this .isMethodCall0 ( rootType , name , arity , derefChain )
2133
+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";" )
2128
2134
|
2129
2135
forall ( Impl impl |
2130
2136
methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2134,15 +2140,15 @@ final class MethodCall extends Call {
2134
2140
|
2135
2141
IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
2136
2142
derefChain + ";" ) , impl , _)
2137
- )
2143
+ ) and
2144
+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
2138
2145
)
2139
2146
}
2140
2147
2141
2148
pragma [ nomagic]
2142
- private Type testgetACandidateReceiverTypeAtNoMatch ( TypePath path , string derefChain ) {
2143
- result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
2144
- this .getLocation ( ) .getStartLine ( ) = 1286 and
2145
- this .fromSource ( )
2149
+ private Type testgetACandidateReceiverTypeAtRef ( TypePath path , string derefChain ) {
2150
+ result = this .getACandidateReceiverTypeAtRef ( path , derefChain ) and
2151
+ this = Debug:: getRelevantLocatable ( )
2146
2152
}
2147
2153
2148
2154
pragma [ nomagic]
@@ -2173,17 +2179,25 @@ final class MethodCall extends Call {
2173
2179
}
2174
2180
2175
2181
pragma [ nomagic]
2176
- private Type testgetACandidateReceiverTypeAtRef ( TypePath path , string derefChain ) {
2177
- result = this .getACandidateReceiverTypeAtRef ( path , derefChain ) and
2178
- this .getLocation ( ) .getStartLine ( ) = 1286 and
2179
- this .fromSource ( )
2182
+ private Type testgetACandidateReceiverTypeAtRefNoMatch ( TypePath path , string derefChain ) {
2183
+ result = this .getACandidateReceiverTypeAtRefNoMatch ( path , derefChain ) and
2184
+ this = Debug:: getRelevantLocatable ( )
2185
+ }
2186
+
2187
+ pragma [ nomagic]
2188
+ private Type testgetACandidateReceiverTypeAtRefNoMatch2 (
2189
+ TypePath path , string derefChain , Type rootType , string name , int arity
2190
+ ) {
2191
+ result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
2192
+ this .isMethodCall0 ( rootType , name , arity , derefChain ) and
2193
+ this = Debug:: getRelevantLocatable ( )
2180
2194
}
2181
2195
2182
2196
pragma [ nomagic]
2183
2197
private Type getACandidateReceiverTypeAtRefNoMatch ( TypePath path , string derefChain ) {
2184
2198
result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
2185
2199
exists ( Type rootType , string name , int arity |
2186
- this .isMethodCall0 ( rootType , name , arity , derefChain )
2200
+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";ref" )
2187
2201
|
2188
2202
forall ( Impl impl |
2189
2203
methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2193,7 +2207,8 @@ final class MethodCall extends Call {
2193
2207
|
2194
2208
IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
2195
2209
derefChain + ";ref" ) , impl , _)
2196
- )
2210
+ ) and
2211
+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
2197
2212
)
2198
2213
}
2199
2214
@@ -2218,19 +2233,22 @@ final class MethodCall extends Call {
2218
2233
t0 = this .getACandidateReceiverTypeAtRef ( path0 , derefChain ) and
2219
2234
derefChainRef = derefChain + ";ref"
2220
2235
|
2221
- path .isEmpty ( ) and
2222
- result = TRefType ( )
2223
- or
2224
- path = TypePath:: cons ( TRefTypeParameter ( ) , path0 ) and
2236
+ // path.isEmpty() and
2237
+ // result = TRefType()
2238
+ // or
2239
+ // path = TypePath::cons(TRefTypeParameter(), path0) and
2240
+ // result = t0
2241
+ path = path0 and
2225
2242
result = t0
2226
2243
)
2227
2244
}
2228
2245
2229
2246
pragma [ nomagic]
2230
2247
private Type testgetACandidateReceiverTypeRefsAt ( TypePath path , string derefChain ) {
2231
2248
result = this .getACandidateReceiverTypeRefsAt ( path , derefChain ) and
2232
- this .getLocation ( ) .getStartLine ( ) = 1286 and
2233
- this .fromSource ( )
2249
+ this = Debug:: getRelevantLocatable ( )
2250
+ // this.getLocation().getStartLine() = 1286 and
2251
+ // this.fromSource()
2234
2252
}
2235
2253
// /** An alias for `getCandidateReceiverTypeAt`, needed to implement `HasTypeTreeSig`. */
2236
2254
// Type getTypeAt(TypePath path) { result = this.getACandidateReceiverTypeRefsAt(path) }
@@ -2521,21 +2539,28 @@ private Function getDynTraitMethod(DynTraitType traitObject, string name, int ar
2521
2539
result = getMethodSuccessor ( traitObject .getTrait ( ) , name , arity )
2522
2540
}
2523
2541
2542
+ bindingset [ t, name, arity]
2543
+ pragma [ inline_late]
2544
+ private Function resolveNonImplMethodCallTarget ( Type t , string name , int arity ) {
2545
+ // The type of the receiver is a type parameter and the method comes from a
2546
+ // trait bound on the type parameter.
2547
+ result = getTypeParameterMethod ( t , name , arity )
2548
+ or
2549
+ // The type of the receiver is an `impl Trait` type.
2550
+ result = getImplTraitMethod ( t , name , arity )
2551
+ or
2552
+ // The type of the receiver is a trait object `dyn Trait` type.
2553
+ result = getDynTraitMethod ( t , name , arity )
2554
+ }
2555
+
2524
2556
pragma [ nomagic]
2525
2557
private Function resolveMethodCallTarget ( MethodCallDerefChainRef mcd ) {
2526
2558
// The method comes from an `impl` block targeting the type of the receiver.
2527
2559
result = getMethodFromImpl ( mcd )
2528
2560
or
2529
- exists ( Type rootType , string name , int arity | isMethodCall ( mcd , _, rootType , name , arity ) |
2530
- // The type of the receiver is a type parameter and the method comes from a
2531
- // trait bound on the type parameter.
2532
- result = getTypeParameterMethod ( rootType , name , arity )
2533
- or
2534
- // The type of the receiver is an `impl Trait` type.
2535
- result = getImplTraitMethod ( rootType , name , arity )
2536
- or
2537
- // The type of the receiver is a trait object `dyn Trait` type.
2538
- result = getDynTraitMethod ( rootType , name , arity )
2561
+ exists ( Type rootType , string name , int arity |
2562
+ isMethodCall ( mcd , _, rootType , name , arity ) and
2563
+ result = resolveNonImplMethodCallTarget ( rootType , name , arity )
2539
2564
)
2540
2565
}
2541
2566
@@ -2853,11 +2878,13 @@ Type inferType(AstNode n) { result = inferType(n, TypePath::nil()) }
2853
2878
2854
2879
/** Provides predicates for debugging the type inference implementation. */
2855
2880
private module Debug {
2856
- private Locatable getRelevantLocatable ( ) {
2881
+ Locatable getRelevantLocatable ( ) {
2857
2882
exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
2858
2883
result .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) and
2859
- filepath .matches ( "%/dereference.rs" ) and
2860
- startline = 171
2884
+ filepath .matches ( "%/crates/wdk-macros/src/lib.rs" ) and
2885
+ startline = [ 254 .. 256 ]
2886
+ // filepath.matches("%/main.rs") and
2887
+ // startline = 708
2861
2888
)
2862
2889
}
2863
2890
0 commit comments