@@ -503,22 +503,20 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
503
503
private predicate paramPos ( ParamList pl , Param p , int pos ) { p = pl .getParam ( pos ) }
504
504
505
505
private newtype TDeclarationPosition =
506
- TSelfDeclarationPosition ( ) or
507
- TPositionalDeclarationPosition ( int pos ) { paramPos ( _, _, pos ) } or
506
+ TArgumentDeclarationPosition ( ArgumentPosition pos ) or
508
507
TReturnDeclarationPosition ( )
509
508
510
509
class DeclarationPosition extends TDeclarationPosition {
511
- predicate isSelf ( ) { this = TSelfDeclarationPosition ( ) }
510
+ predicate isSelf ( ) { this . asArgumentPosition ( ) . isSelf ( ) }
512
511
513
- int asPosition ( ) { this = TPositionalDeclarationPosition ( result ) }
512
+ int asPosition ( ) { result = this .asArgumentPosition ( ) .asPosition ( ) }
513
+
514
+ ArgumentPosition asArgumentPosition ( ) { this = TArgumentDeclarationPosition ( result ) }
514
515
515
516
predicate isReturn ( ) { this = TReturnDeclarationPosition ( ) }
516
517
517
518
string toString ( ) {
518
- this .isSelf ( ) and
519
- result = "self"
520
- or
521
- result = this .asPosition ( ) .toString ( )
519
+ result = this .asArgumentPosition ( ) .toString ( )
522
520
or
523
521
this .isReturn ( ) and
524
522
result = "(return)"
@@ -551,7 +549,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
551
549
override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
552
550
exists ( int pos |
553
551
result = this .getTupleField ( pos ) .getTypeRepr ( ) .( TypeMention ) .resolveTypeAt ( path ) and
554
- dpos = TPositionalDeclarationPosition ( pos )
552
+ pos = dpos . asPosition ( )
555
553
)
556
554
}
557
555
@@ -572,9 +570,9 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
572
570
}
573
571
574
572
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 ( )
578
576
)
579
577
}
580
578
@@ -609,7 +607,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
609
607
override Type getParameterType ( DeclarationPosition dpos , TypePath path ) {
610
608
exists ( Param p , int i |
611
609
paramPos ( this .getParamList ( ) , p , i ) and
612
- dpos = TPositionalDeclarationPosition ( i ) and
610
+ i = dpos . asPosition ( ) and
613
611
result = inferAnnotatedType ( p .getPat ( ) , path )
614
612
)
615
613
or
@@ -642,22 +640,21 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
642
640
}
643
641
644
642
private newtype TAccessPosition =
645
- TSelfAccessPosition ( Boolean implicitlyBorrowed ) or
646
- TPositionalAccessPosition ( int pos ) { exists ( TPositionalDeclarationPosition ( pos ) ) } or
643
+ TArgumentAccessPosition ( ArgumentPosition pos , Boolean borrowed ) or
647
644
TReturnAccessPosition ( )
648
645
649
646
class AccessPosition extends TAccessPosition {
650
- predicate isSelf ( boolean implicitlyBorrowed ) { this = TSelfAccessPosition ( implicitlyBorrowed ) }
647
+ ArgumentPosition getArgumentPosition ( ) { this = TArgumentAccessPosition ( result , _ ) }
651
648
652
- int asPosition ( ) { this = TPositionalAccessPosition ( result ) }
649
+ predicate isBorrowed ( ) { this = TArgumentAccessPosition ( _ , true ) }
653
650
654
651
predicate isReturn ( ) { this = TReturnAccessPosition ( ) }
655
652
656
653
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
+ )
661
658
or
662
659
this .isReturn ( ) and
663
660
result = "(return)"
@@ -677,10 +674,11 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
677
674
}
678
675
679
676
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
+ )
684
682
or
685
683
result = this and apos .isReturn ( )
686
684
}
@@ -697,9 +695,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
697
695
}
698
696
699
697
predicate accessDeclarationPositionMatch ( AccessPosition apos , DeclarationPosition dpos ) {
700
- apos .isSelf ( _) and dpos .isSelf ( )
701
- or
702
- apos .asPosition ( ) = dpos .asPosition ( )
698
+ apos .getArgumentPosition ( ) = dpos .asArgumentPosition ( )
703
699
or
704
700
apos .isReturn ( ) and dpos .isReturn ( )
705
701
}
@@ -709,10 +705,13 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
709
705
predicate adjustAccessType (
710
706
AccessPosition apos , Declaration target , TypePath path , Type t , TypePath pathAdj , Type tAdj
711
707
) {
712
- if apos .isSelf ( true )
708
+ if apos .getArgumentPosition ( ) . isSelf ( ) and apos . isBorrowed ( )
713
709
then
714
710
exists ( Type selfParamType |
715
- selfParamType = target .getParameterType ( TSelfDeclarationPosition ( ) , TypePath:: nil ( ) )
711
+ selfParamType =
712
+ target
713
+ .getParameterType ( TArgumentDeclarationPosition ( apos .getArgumentPosition ( ) ) ,
714
+ TypePath:: nil ( ) )
716
715
|
717
716
if selfParamType = TRefType ( )
718
717
then
@@ -771,7 +770,7 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
771
770
// temporary workaround until implicit borrows are handled correctly
772
771
if a instanceof Operation then apos .isReturn ( ) else any ( )
773
772
|
774
- if apos .isSelf ( _ )
773
+ if apos .getArgumentPosition ( ) . isSelf ( )
775
774
then
776
775
exists ( Type receiverType | receiverType = inferType ( n ) |
777
776
if receiverType = TRefType ( )
@@ -1356,7 +1355,7 @@ private Function getMethodFromImpl(MethodCall mc) {
1356
1355
or
1357
1356
exists ( int pos , TypePath path , Type type |
1358
1357
methodResolutionDependsOnArgument ( impl , mc .getMethodName ( ) , result , pos , path , type ) and
1359
- inferType ( mc .getArgument ( pos ) , path ) = type
1358
+ inferType ( mc .getPositionalArgument ( pos ) , path ) = type
1360
1359
)
1361
1360
)
1362
1361
}
@@ -1391,7 +1390,8 @@ private module Cached {
1391
1390
cached
1392
1391
predicate receiverHasImplicitDeref ( AstNode receiver ) {
1393
1392
exists ( CallExprBaseMatchingInput:: Access a , CallExprBaseMatchingInput:: AccessPosition apos |
1394
- apos .isSelf ( true ) and
1393
+ apos .getArgumentPosition ( ) .isSelf ( ) and
1394
+ apos .isBorrowed ( ) and
1395
1395
receiver = a .getNodeAt ( apos ) and
1396
1396
inferType ( receiver ) = TRefType ( ) and
1397
1397
CallExprBaseMatching:: inferAccessType ( a , apos , TypePath:: nil ( ) ) != TRefType ( )
@@ -1402,7 +1402,8 @@ private module Cached {
1402
1402
cached
1403
1403
predicate receiverHasImplicitBorrow ( AstNode receiver ) {
1404
1404
exists ( CallExprBaseMatchingInput:: Access a , CallExprBaseMatchingInput:: AccessPosition apos |
1405
- apos .isSelf ( true ) and
1405
+ apos .getArgumentPosition ( ) .isSelf ( ) and
1406
+ apos .isBorrowed ( ) and
1406
1407
receiver = a .getNodeAt ( apos ) and
1407
1408
CallExprBaseMatching:: inferAccessType ( a , apos , TypePath:: nil ( ) ) = TRefType ( ) and
1408
1409
inferType ( receiver ) != TRefType ( )
0 commit comments