@@ -22,7 +22,7 @@ private module Input1 implements InputSig1<Location> {
2222 // method type parameters are matched by position instead of by type
2323 // parameter entity, to avoid extra recursion through method call resolution
2424 TMethodTypeArgumentPosition ( int pos ) {
25- exists ( any ( MethodCallExpr mce ) .getGenericArgList ( ) .getTypeArgument ( pos ) )
25+ exists ( any ( MethodCallExpr mce ) .getGenericArgList ( ) .getTypeArg ( pos ) )
2626 } or
2727 TTypeParamTypeArgumentPosition ( TypeParam tp )
2828
@@ -124,11 +124,13 @@ private Type inferAnnotatedType(AstNode n, TypePath path) {
124124}
125125
126126/**
127- * Holds if the type of `n1` at `path1` is the same as the type of `n2` at `path2`.
127+ * Holds if the type of `n1` at `path1` is the same as the type of `n2` at
128+ * `path2` and type information should propagate in both directions through the
129+ * type equality.
128130 */
129131bindingset [ path1]
130132bindingset [ path2]
131- private predicate typeSymmetry ( AstNode n1 , TypePath path1 , AstNode n2 , TypePath path2 ) {
133+ private predicate typeEquality ( AstNode n1 , TypePath path1 , AstNode n2 , TypePath path2 ) {
132134 exists ( Variable v |
133135 path1 = path2 and
134136 n1 = v .getAnAccess ( )
@@ -159,11 +161,11 @@ private predicate typeSymmetry(AstNode n1, TypePath path1, AstNode n2, TypePath
159161}
160162
161163pragma [ nomagic]
162- private Type inferTypeSymmetry ( AstNode n , TypePath path ) {
164+ private Type inferTypeEquality ( AstNode n , TypePath path ) {
163165 exists ( AstNode n2 , TypePath path2 | result = inferType ( n2 , path2 ) |
164- typeSymmetry ( n , path , n2 , path2 )
166+ typeEquality ( n , path , n2 , path2 )
165167 or
166- typeSymmetry ( n2 , path2 , n , path )
168+ typeEquality ( n2 , path2 , n , path )
167169 )
168170}
169171
@@ -222,7 +224,7 @@ private Type inferImplicitSelfType(SelfParam self, TypePath path) {
222224
223225private TypeMention getExplicitTypeArgMention ( Path path , TypeParam tp ) {
224226 exists ( int i |
225- result = path .getPart ( ) .getGenericArgList ( ) .getTypeArgument ( pragma [ only_bind_into ] ( i ) ) and
227+ result = path .getPart ( ) .getGenericArgList ( ) .getTypeArg ( pragma [ only_bind_into ] ( i ) ) and
226228 tp = resolvePath ( path ) .getTypeParam ( pragma [ only_bind_into ] ( i ) )
227229 )
228230 or
@@ -316,7 +318,7 @@ private module RecordExprMatchingInput implements MatchingInputSig {
316318 class AccessPosition = DeclarationPosition ;
317319
318320 class Access extends RecordExpr {
319- Type getExplicitTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
321+ Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
320322 result = getExplicitTypeArgMention ( this .getPath ( ) , apos .asTypeParam ( ) ) .resolveTypeAt ( path )
321323 }
322324
@@ -535,10 +537,10 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
535537
536538 class Access extends CallExprBase {
537539 private TypeReprMention getMethodTypeArg ( int i ) {
538- result = this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArgument ( i )
540+ result = this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArg ( i )
539541 }
540542
541- Type getExplicitTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
543+ Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
542544 exists ( TypeMention arg | result = arg .resolveTypeAt ( path ) |
543545 arg = getExplicitTypeArgMention ( CallExprImpl:: getFunctionPath ( this ) , apos .asTypeParam ( ) )
544546 or
@@ -616,7 +618,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
616618 pathAdj = TypePath:: singleton ( TRefTypeParameter ( ) ) and
617619 tAdj = t
618620 else
619- if path .startsWith ( TRefTypeParameter ( ) , _)
621+ if path .isCons ( TRefTypeParameter ( ) , _)
620622 then
621623 pathAdj = path and
622624 tAdj = t
@@ -628,10 +630,10 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
628630 )
629631 else (
630632 // adjust for implicit deref
631- path .startsWith ( TRefTypeParameter ( ) , pathAdj ) and
633+ path .isCons ( TRefTypeParameter ( ) , pathAdj ) and
632634 tAdj = t
633635 or
634- not path .startsWith ( TRefTypeParameter ( ) , _) and
636+ not path .isCons ( TRefTypeParameter ( ) , _) and
635637 not ( t = TRefType ( ) and path .isEmpty ( ) ) and
636638 pathAdj = path and
637639 tAdj = t
@@ -674,19 +676,19 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
674676 if receiverType = TRefType ( )
675677 then
676678 path = path0 and
677- path0 .startsWith ( TRefTypeParameter ( ) , _)
679+ path0 .isCons ( TRefTypeParameter ( ) , _)
678680 or
679681 // adjust for implicit deref
680- not path0 .startsWith ( TRefTypeParameter ( ) , _) and
682+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
681683 not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
682684 path = TypePath:: cons ( TRefTypeParameter ( ) , path0 )
683685 else (
684- not path0 .startsWith ( TRefTypeParameter ( ) , _) and
686+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
685687 not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
686688 path = path0
687689 or
688690 // adjust for implicit borrow
689- path0 .startsWith ( TRefTypeParameter ( ) , path )
691+ path0 .isCons ( TRefTypeParameter ( ) , path )
690692 )
691693 )
692694 else path = path0
@@ -748,7 +750,7 @@ private module FieldExprMatchingInput implements MatchingInputSig {
748750 class AccessPosition = DeclarationPosition ;
749751
750752 class Access extends FieldExpr {
751- Type getExplicitTypeArgument ( TypeArgumentPosition apos , TypePath path ) { none ( ) }
753+ Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) { none ( ) }
752754
753755 AstNode getNodeAt ( AccessPosition apos ) {
754756 result = this .getExpr ( ) and
@@ -781,10 +783,10 @@ private module FieldExprMatchingInput implements MatchingInputSig {
781783 if apos .isSelf ( )
782784 then
783785 // adjust for implicit deref
784- path .startsWith ( TRefTypeParameter ( ) , pathAdj ) and
786+ path .isCons ( TRefTypeParameter ( ) , pathAdj ) and
785787 tAdj = t
786788 or
787- not path .startsWith ( TRefTypeParameter ( ) , _) and
789+ not path .isCons ( TRefTypeParameter ( ) , _) and
788790 not ( t = TRefType ( ) and path .isEmpty ( ) ) and
789791 pathAdj = path and
790792 tAdj = t
@@ -824,7 +826,7 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
824826 if receiverType = TRefType ( )
825827 then
826828 // adjust for implicit deref
827- not path0 .startsWith ( TRefTypeParameter ( ) , _) and
829+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
828830 not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
829831 path = TypePath:: cons ( TRefTypeParameter ( ) , path0 )
830832 else path = path0
@@ -846,7 +848,7 @@ private Type inferRefExprType(Expr e, TypePath path) {
846848 or
847849 e = re and
848850 exists ( TypePath exprPath | result = inferType ( re .getExpr ( ) , exprPath ) |
849- if exprPath .startsWith ( TRefTypeParameter ( ) , _)
851+ if exprPath .isCons ( TRefTypeParameter ( ) , _)
850852 then
851853 // `&x` simply means `x` when `x` already has reference type
852854 path = exprPath
@@ -975,7 +977,7 @@ private module Cached {
975977 Stages:: TypeInference:: backref ( ) and
976978 result = inferAnnotatedType ( n , path )
977979 or
978- result = inferTypeSymmetry ( n , path )
980+ result = inferTypeEquality ( n , path )
979981 or
980982 result = inferImplicitSelfType ( n , path )
981983 or
0 commit comments