@@ -1283,8 +1283,9 @@ private Type testinferCallExprBaseType(
12831283 CallExprBaseMatchingInput:: Access a , string state , CallExprBaseMatchingInput:: AccessPosition apos ,
12841284 TypePath path
12851285) {
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
12881289 result = CallExprBaseMatching:: inferAccessType ( a , state , apos , path )
12891290}
12901291
@@ -2068,11 +2069,16 @@ final class MethodCall extends Call {
20682069
20692070 pragma [ nomagic]
20702071 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
20722073 name = this .getMethodName ( ) and
20732074 arity = this .getNumberOfArguments ( )
20742075 }
20752076
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+
20762082 /**
20772083 * Gets a [candidate receiver type][1] of this method call.
20782084 *
@@ -2124,7 +2130,7 @@ final class MethodCall extends Call {
21242130 this .receiverImplicitlyBorrowed ( ) and
21252131 result = this .getACandidateReceiverTypeAt ( path , derefChain ) and
21262132 exists ( Type rootType , string name , int arity |
2127- this .isMethodCall0 ( rootType , name , arity , derefChain )
2133+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";" )
21282134 |
21292135 forall ( Impl impl |
21302136 methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2134,15 +2140,15 @@ final class MethodCall extends Call {
21342140 |
21352141 IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
21362142 derefChain + ";" ) , impl , _)
2137- )
2143+ ) and
2144+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
21382145 )
21392146 }
21402147
21412148 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 ( )
21462152 }
21472153
21482154 pragma [ nomagic]
@@ -2173,17 +2179,25 @@ final class MethodCall extends Call {
21732179 }
21742180
21752181 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 ( )
21802194 }
21812195
21822196 pragma [ nomagic]
21832197 private Type getACandidateReceiverTypeAtRefNoMatch ( TypePath path , string derefChain ) {
21842198 result = this .getACandidateReceiverTypeAtNoMatch ( path , derefChain ) and
21852199 exists ( Type rootType , string name , int arity |
2186- this .isMethodCall0 ( rootType , name , arity , derefChain )
2200+ this .isMethodCall0 ( rootType , name , arity , derefChain + ";ref" )
21872201 |
21882202 forall ( Impl impl |
21892203 methodCandidateTrait ( rootType , this .getTrait ( ) , name , arity , impl )
@@ -2193,7 +2207,8 @@ final class MethodCall extends Call {
21932207 |
21942208 IsInstantiationOf< MethodCallDerefChainRef , IsInstantiationOfInput > :: isNotInstantiationOf ( MkMethodCallDerefChainRef ( this ,
21952209 derefChain + ";ref" ) , impl , _)
2196- )
2210+ ) and
2211+ not exists ( resolveNonImplMethodCallTarget ( rootType , name , arity ) )
21972212 )
21982213 }
21992214
@@ -2218,19 +2233,22 @@ final class MethodCall extends Call {
22182233 t0 = this .getACandidateReceiverTypeAtRef ( path0 , derefChain ) and
22192234 derefChainRef = derefChain + ";ref"
22202235 |
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
22252242 result = t0
22262243 )
22272244 }
22282245
22292246 pragma [ nomagic]
22302247 private Type testgetACandidateReceiverTypeRefsAt ( TypePath path , string derefChain ) {
22312248 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()
22342252 }
22352253 // /** An alias for `getCandidateReceiverTypeAt`, needed to implement `HasTypeTreeSig`. */
22362254 // Type getTypeAt(TypePath path) { result = this.getACandidateReceiverTypeRefsAt(path) }
@@ -2521,21 +2539,28 @@ private Function getDynTraitMethod(DynTraitType traitObject, string name, int ar
25212539 result = getMethodSuccessor ( traitObject .getTrait ( ) , name , arity )
25222540}
25232541
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+
25242556pragma [ nomagic]
25252557private Function resolveMethodCallTarget ( MethodCallDerefChainRef mcd ) {
25262558 // The method comes from an `impl` block targeting the type of the receiver.
25272559 result = getMethodFromImpl ( mcd )
25282560 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 )
25392564 )
25402565}
25412566
@@ -2853,11 +2878,13 @@ Type inferType(AstNode n) { result = inferType(n, TypePath::nil()) }
28532878
28542879/** Provides predicates for debugging the type inference implementation. */
28552880private module Debug {
2856- private Locatable getRelevantLocatable ( ) {
2881+ Locatable getRelevantLocatable ( ) {
28572882 exists ( string filepath , int startline , int startcolumn , int endline , int endcolumn |
28582883 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
28612888 )
28622889 }
28632890
0 commit comments