@@ -343,8 +343,8 @@ private class FunctionDeclaration extends Function {
343343 }
344344}
345345
346- private class AssocFunction extends FunctionDeclaration {
347- AssocFunction ( ) { this .isAssoc ( _) }
346+ private class AssocFunctionDeclaration extends FunctionDeclaration {
347+ AssocFunctionDeclaration ( ) { this .isAssoc ( _) }
348348}
349349
350350pragma [ nomagic]
@@ -1114,10 +1114,10 @@ private Trait getCallExprTraitQualifier(CallExpr ce) {
11141114}
11151115
11161116pragma [ nomagic]
1117- private predicate nonAssocFunction ( ItemNode i ) { not i instanceof AssocFunction }
1117+ private predicate nonAssocFunction ( ItemNode i ) { not i instanceof AssocFunctionDeclaration }
11181118
11191119/**
1120- * A call expression that can resolve to something that is not an associated
1120+ * A call expression that can only resolve to something that is not an associated
11211121 * function, and hence does not need type inference for resolution.
11221122 */
11231123private class NonAssocCallExpr extends CallExpr {
@@ -1201,9 +1201,7 @@ private module ContextTyping {
12011201 abstract class ContextTypedCallCand extends AstNode {
12021202 abstract Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) ;
12031203
1204- private predicate hasTypeArgument ( TypeArgumentPosition apos ) {
1205- exists ( this .getTypeArgument ( apos , _) )
1206- }
1204+ predicate hasTypeArgument ( TypeArgumentPosition apos ) { exists ( this .getTypeArgument ( apos , _) ) }
12071205
12081206 /**
12091207 * Holds if this call resolves to `target` inside `i`, and the return type
@@ -2209,7 +2207,7 @@ private module AssocFunctionResolution {
22092207 * in `derefChain` and `borrow`.
22102208 */
22112209 pragma [ nomagic]
2212- AssocFunction resolveCallTarget (
2210+ AssocFunctionDeclaration resolveCallTarget (
22132211 ImplOrTraitItemNode i , FunctionPosition selfPos , DerefChain derefChain , BorrowKind borrow
22142212 ) {
22152213 exists ( AssocFunctionCallCand afcc |
@@ -2288,7 +2286,9 @@ private module AssocFunctionResolution {
22882286 exists ( getCallExprPathQualifier ( this ) ) and
22892287 // even if a target cannot be resolved by path resolution, it may still
22902288 // be possible to resolve a blanket implementation (so not `forex`)
2291- forall ( ItemNode i | i = CallExprImpl:: getResolvedFunction ( this ) | i instanceof AssocFunction )
2289+ forall ( ItemNode i | i = CallExprImpl:: getResolvedFunction ( this ) |
2290+ i instanceof AssocFunctionDeclaration
2291+ )
22922292 }
22932293
22942294 override predicate hasNameAndArity ( string name , int arity ) {
@@ -2373,7 +2373,9 @@ private module AssocFunctionResolution {
23732373 }
23742374
23752375 pragma [ nomagic]
2376- private AssocFunction getAssocFunctionSuccessor ( ImplOrTraitItemNode i , string name , int arity ) {
2376+ private AssocFunctionDeclaration getAssocFunctionSuccessor (
2377+ ImplOrTraitItemNode i , string name , int arity
2378+ ) {
23772379 result = i .getASuccessor ( name ) and
23782380 arity = result .getNumberOfParamsInclSelf ( )
23792381 }
@@ -2488,7 +2490,7 @@ private module AssocFunctionResolution {
24882490 }
24892491
24902492 pragma [ nomagic]
2491- AssocFunction resolveCallTargetCand ( ImplOrTraitItemNode i ) {
2493+ AssocFunctionDeclaration resolveCallTargetCand ( ImplOrTraitItemNode i ) {
24922494 exists ( string name , int arity |
24932495 this .selfArgIsInstantiationOf ( i , name , arity ) and
24942496 result = getAssocFunctionSuccessor ( i , name , arity )
@@ -2497,7 +2499,7 @@ private module AssocFunctionResolution {
24972499
24982500 /** Gets the associated function targeted by this call, if any. */
24992501 pragma [ nomagic]
2500- AssocFunction resolveCallTarget ( ImplOrTraitItemNode i ) {
2502+ AssocFunctionDeclaration resolveCallTarget ( ImplOrTraitItemNode i ) {
25012503 result = this .resolveCallTargetCand ( i ) and
25022504 not FunctionOverloading:: functionResolutionDependsOnArgument ( i , result , _, _)
25032505 or
@@ -2896,18 +2898,15 @@ private module FunctionCallMatchingInput implements MatchingWithEnvironmentInput
28962898 result = this .getInferredNonSelfType ( pos , path )
28972899 }
28982900
2899- private AssocFunction getTarget ( ImplOrTraitItemNode i , string derefChainBorrow ) {
2901+ private AssocFunctionDeclaration getTarget ( ImplOrTraitItemNode i , string derefChainBorrow ) {
29002902 exists ( DerefChain derefChain , BorrowKind borrow |
29012903 derefChainBorrow = encodeDerefChainBorrow ( derefChain , borrow ) and
29022904 result = super .resolveCallTarget ( i , _, derefChain , borrow ) // mutual recursion; resolving method calls requires resolving types and vice versa
29032905 )
29042906 }
29052907
29062908 override Declaration getTarget ( string derefChainBorrow ) {
2907- exists ( ImplOrTraitItemNodeOption i , AssocFunction f |
2908- f = this .getTarget ( i .asSome ( ) , derefChainBorrow ) and
2909- result = TFunctionDeclaration ( i , f )
2910- )
2909+ exists ( ImplOrTraitItemNode i | result .isAssocFunction ( i , this .getTarget ( i , derefChainBorrow ) ) )
29112910 }
29122911
29132912 pragma [ nomagic]
@@ -2926,7 +2925,9 @@ private module FunctionCallMatchingInput implements MatchingWithEnvironmentInput
29262925 }
29272926 }
29282927
2929- private class NonAssocFunctionCallAccess extends Access instanceof NonAssocCallExpr {
2928+ private class NonAssocFunctionCallAccess extends Access instanceof NonAssocCallExpr ,
2929+ CallExprImpl:: CallExprCall
2930+ {
29302931 pragma [ nomagic]
29312932 override Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
29322933 result = NonAssocCallExpr .super .getTypeArgument ( apos , path )
@@ -2949,11 +2950,9 @@ private module FunctionCallMatchingInput implements MatchingWithEnvironmentInput
29492950
29502951 pragma [ nomagic]
29512952 private Declaration getTarget ( ) {
2952- exists ( ImplOrTraitItemNodeOption i , FunctionDeclaration f |
2953- f = super .resolveCallTargetViaPathResolution ( ) and
2954- f .isDirectlyFor ( i ) and
2955- result = TFunctionDeclaration ( i , f )
2956- )
2953+ result =
2954+ TFunctionDeclaration ( ImplOrTraitItemNodeOption:: none_ ( ) ,
2955+ super .resolveCallTargetViaPathResolution ( ) )
29572956 }
29582957
29592958 override Declaration getTarget ( string derefChainBorrow ) {
@@ -2964,9 +2963,16 @@ private module FunctionCallMatchingInput implements MatchingWithEnvironmentInput
29642963 pragma [ nomagic]
29652964 override predicate hasUnknownTypeAt ( string derefChainBorrow , FunctionPosition pos , TypePath path ) {
29662965 derefChainBorrow = noDerefChainBorrow ( ) and
2967- exists ( ImplOrTraitItemNodeOption i , FunctionDeclaration f |
2968- TFunctionDeclaration ( i , f ) = this .getTarget ( ) and
2969- this .hasUnknownTypeAt ( i .asSome ( ) , f , pos , path )
2966+ exists ( FunctionDeclaration f , TypeParameter tp |
2967+ f = super .resolveCallTargetViaPathResolution ( ) and
2968+ pos .isReturn ( ) and
2969+ tp = f .getReturnType ( _, path ) and
2970+ not tp = f .getParameterType ( _, _, _) and
2971+ // check that no explicit type arguments have been supplied for `tp`
2972+ not exists ( TypeArgumentPosition tapos |
2973+ this .hasTypeArgument ( tapos ) and
2974+ TTypeParamTypeParameter ( tapos .asTypeParam ( ) ) = tp
2975+ )
29702976 )
29712977 }
29722978 }
@@ -3135,6 +3141,11 @@ private module TupleLikeConstructionMatchingInput implements MatchingInputSig {
31353141 class Declaration = TupleLikeConstructor ;
31363142
31373143 class Access extends NonAssocCallExpr , ContextTyping:: ContextTypedCallCand {
3144+ Access ( ) {
3145+ this instanceof CallExprImpl:: TupleStructExpr or
3146+ this instanceof CallExprImpl:: TupleVariantExpr
3147+ }
3148+
31383149 override Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
31393150 result = NonAssocCallExpr .super .getTypeArgument ( apos , path )
31403151 }
0 commit comments