@@ -503,22 +503,20 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
503503 private predicate paramPos ( ParamList pl , Param p , int pos ) { p = pl .getParam ( pos ) }
504504
505505 private newtype TDeclarationPosition =
506- TSelfDeclarationPosition ( ) or
507- TPositionalDeclarationPosition ( int pos ) { paramPos ( _, _, pos ) } or
506+ TArgumentDeclarationPosition ( ArgumentPosition pos ) or
508507 TReturnDeclarationPosition ( )
509508
510509 class DeclarationPosition extends TDeclarationPosition {
511- predicate isSelf ( ) { this = TSelfDeclarationPosition ( ) }
510+ predicate isSelf ( ) { this . asArgumentPosition ( ) . isSelf ( ) }
512511
513- int asPosition ( ) { this = TPositionalDeclarationPosition ( result ) }
512+ int asPosition ( ) { result = this .asArgumentPosition ( ) .asPosition ( ) }
513+
514+ ArgumentPosition asArgumentPosition ( ) { this = TArgumentDeclarationPosition ( result ) }
514515
515516 predicate isReturn ( ) { this = TReturnDeclarationPosition ( ) }
516517
517518 string toString ( ) {
518- this .isSelf ( ) and
519- result = "self"
520- or
521- result = this .asPosition ( ) .toString ( )
519+ result = this .asArgumentPosition ( ) .toString ( )
522520 or
523521 this .isReturn ( ) and
524522 result = "(return)"
@@ -551,7 +549,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
551549 override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
552550 exists ( int pos |
553551 result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path ) and
554- dpos = TPositionalDeclarationPosition ( pos )
552+ pos = dpos . asPosition ( )
555553 )
556554 }
557555
@@ -572,9 +570,9 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
572570 }
573571
574572 override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
575- exists ( int p |
576- result = this .getTupleField ( p ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path ) and
577- dpos = TPositionalDeclarationPosition ( p )
573+ exists ( int pos |
574+ result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path ) and
575+ pos = dpos . asPosition ( )
578576 )
579577 }
580578
@@ -609,7 +607,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
609607 override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
610608 exists ( Param p , int i |
611609 paramPos ( this .getParamList ( ) , p , i ) and
612- dpos = TPositionalDeclarationPosition ( i ) and
610+ i = dpos . asPosition ( ) and
613611 result = inferAnnotatedType ( p .getPat ( ) , path )
614612 )
615613 or
@@ -642,22 +640,21 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
642640 }
643641
644642 private newtype TAccessPosition =
645- TSelfAccessPosition ( Boolean implicitlyBorrowed ) or
646- TPositionalAccessPosition ( int pos ) { exists ( TPositionalDeclarationPosition ( pos ) ) } or
643+ TArgumentAccessPosition ( ArgumentPosition pos , Boolean borrowed ) or
647644 TReturnAccessPosition ( )
648645
649646 class AccessPosition extends TAccessPosition {
650- predicate isSelf ( boolean implicitlyBorrowed ) { this = TSelfAccessPosition ( implicitlyBorrowed ) }
647+ ArgumentPosition getArgumentPosition ( ) { this = TArgumentAccessPosition ( result , _ ) }
651648
652- int asPosition ( ) { this = TPositionalAccessPosition ( result ) }
649+ predicate isBorrowed ( ) { this = TArgumentAccessPosition ( _ , true ) }
653650
654651 predicate isReturn ( ) { this = TReturnAccessPosition ( ) }
655652
656653 string toString ( ) {
657- this . isSelf ( _ ) and
658- result = "self"
659- or
660- result = this . asPosition ( ) . toString ( )
654+ exists ( ArgumentPosition pos , boolean borrowed |
655+ this = TArgumentAccessPosition ( pos , borrowed ) and
656+ result = pos + ":" + borrowed
657+ )
661658 or
662659 this .isReturn ( ) and
663660 result = "(return)"
@@ -677,10 +674,11 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
677674 }
678675
679676 AstNode getNodeAt ( AccessPosition apos ) {
680- result = this .getArgument ( apos .asPosition ( ) )
681- or
682- result = this .getReceiver ( ) and
683- if this .receiverImplicitlyBorrowed ( ) then apos .isSelf ( true ) else apos .isSelf ( false )
677+ exists ( ArgumentPosition pos , boolean borrowed |
678+ apos = TArgumentAccessPosition ( pos , borrowed ) and
679+ result = this .getArgument ( pos ) and
680+ if this .implicitBorrowAt ( pos ) then borrowed = true else borrowed = false
681+ )
684682 or
685683 result = this and apos .isReturn ( )
686684 }
@@ -697,9 +695,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
697695 }
698696
699697 predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) {
700- apos .isSelf ( _) and dpos .isSelf ( )
701- or
702- apos .asPosition ( ) = dpos .asPosition ( )
698+ apos .getArgumentPosition ( ) = dpos .asArgumentPosition ( )
703699 or
704700 apos .isReturn ( ) and dpos .isReturn ( )
705701 }
@@ -709,10 +705,13 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
709705 predicate adjustAccessType (
710706 AccessPosition apos , Declaration target , TypePath path , Type t , TypePath pathAdj , Type tAdj
711707 ) {
712- if apos .isSelf ( true )
708+ if apos .getArgumentPosition ( ) . isSelf ( ) and apos . isBorrowed ( )
713709 then
714710 exists ( Type selfParamType |
715- selfParamType = target .getParameterType ( TSelfDeclarationPosition ( ) , TypePath:: nil ( ) )
711+ selfParamType =
712+ target
713+ .getParameterType ( TArgumentDeclarationPosition ( apos .getArgumentPosition ( ) ) ,
714+ TypePath:: nil ( ) )
716715 |
717716 if selfParamType = TRefType ( )
718717 then
@@ -771,7 +770,7 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
771770 // temporary workaround until implicit borrows are handled correctly
772771 if a instanceof Operation then apos .isReturn ( ) else any ( )
773772 |
774- if apos .isSelf ( _ )
773+ if apos .getArgumentPosition ( ) . isSelf ( )
775774 then
776775 exists ( Type receiverType | receiverType = inferType ( n ) |
777776 if receiverType = TRefType ( )
@@ -1356,7 +1355,7 @@ private Function getMethodFromImpl(MethodCall mc) {
13561355 or
13571356 exists ( int pos , TypePath path , Type type |
13581357 methodResolutionDependsOnArgument ( impl , mc .getMethodName ( ) , result , pos , path , type ) and
1359- inferType ( mc .getArgument ( pos ) , path ) = type
1358+ inferType ( mc .getPositionalArgument ( pos ) , path ) = type
13601359 )
13611360 )
13621361}
@@ -1391,7 +1390,8 @@ private module Cached {
13911390 cached
13921391 predicate receiverHasImplicitDeref ( AstNode receiver ) {
13931392 exists ( CallExprBaseMatchingInput:: Access a , CallExprBaseMatchingInput:: AccessPosition apos |
1394- apos .isSelf ( true ) and
1393+ apos .getArgumentPosition ( ) .isSelf ( ) and
1394+ apos .isBorrowed ( ) and
13951395 receiver = a .getNodeAt ( apos ) and
13961396 inferType ( receiver ) = TRefType ( ) and
13971397 CallExprBaseMatching:: inferAccessType ( a , apos , TypePath:: nil ( ) ) != TRefType ( )
@@ -1402,7 +1402,8 @@ private module Cached {
14021402 cached
14031403 predicate receiverHasImplicitBorrow ( AstNode receiver ) {
14041404 exists ( CallExprBaseMatchingInput:: Access a , CallExprBaseMatchingInput:: AccessPosition apos |
1405- apos .isSelf ( true ) and
1405+ apos .getArgumentPosition ( ) .isSelf ( ) and
1406+ apos .isBorrowed ( ) and
14061407 receiver = a .getNodeAt ( apos ) and
14071408 CallExprBaseMatching:: inferAccessType ( a , apos , TypePath:: nil ( ) ) = TRefType ( ) and
14081409 inferType ( receiver ) != TRefType ( )
0 commit comments