@@ -22,7 +22,7 @@ private module Input1 implements InputSig1<Location> {
22
22
// method type parameters are matched by position instead of by type
23
23
// parameter entity, to avoid extra recursion through method call resolution
24
24
TMethodTypeArgumentPosition ( int pos ) {
25
- exists ( any ( MethodCallExpr mce ) .getGenericArgList ( ) .getTypeArgument ( pos ) )
25
+ exists ( any ( MethodCallExpr mce ) .getGenericArgList ( ) .getTypeArg ( pos ) )
26
26
} or
27
27
TTypeParamTypeArgumentPosition ( TypeParam tp )
28
28
@@ -124,11 +124,13 @@ private Type inferAnnotatedType(AstNode n, TypePath path) {
124
124
}
125
125
126
126
/**
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.
128
130
*/
129
131
bindingset [ path1]
130
132
bindingset [ 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 ) {
132
134
exists ( Variable v |
133
135
path1 = path2 and
134
136
n1 = v .getAnAccess ( )
@@ -159,11 +161,11 @@ private predicate typeSymmetry(AstNode n1, TypePath path1, AstNode n2, TypePath
159
161
}
160
162
161
163
pragma [ nomagic]
162
- private Type inferTypeSymmetry ( AstNode n , TypePath path ) {
164
+ private Type inferTypeEquality ( AstNode n , TypePath path ) {
163
165
exists ( AstNode n2 , TypePath path2 | result = inferType ( n2 , path2 ) |
164
- typeSymmetry ( n , path , n2 , path2 )
166
+ typeEquality ( n , path , n2 , path2 )
165
167
or
166
- typeSymmetry ( n2 , path2 , n , path )
168
+ typeEquality ( n2 , path2 , n , path )
167
169
)
168
170
}
169
171
@@ -222,7 +224,7 @@ private Type inferImplicitSelfType(SelfParam self, TypePath path) {
222
224
223
225
private TypeMention getExplicitTypeArgMention ( Path path , TypeParam tp ) {
224
226
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
226
228
tp = resolvePath ( path ) .getTypeParam ( pragma [ only_bind_into ] ( i ) )
227
229
)
228
230
or
@@ -316,7 +318,7 @@ private module RecordExprMatchingInput implements MatchingInputSig {
316
318
class AccessPosition = DeclarationPosition ;
317
319
318
320
class Access extends RecordExpr {
319
- Type getExplicitTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
321
+ Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
320
322
result = getExplicitTypeArgMention ( this .getPath ( ) , apos .asTypeParam ( ) ) .resolveTypeAt ( path )
321
323
}
322
324
@@ -535,10 +537,10 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
535
537
536
538
class Access extends CallExprBase {
537
539
private TypeReprMention getMethodTypeArg ( int i ) {
538
- result = this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArgument ( i )
540
+ result = this .( MethodCallExpr ) .getGenericArgList ( ) .getTypeArg ( i )
539
541
}
540
542
541
- Type getExplicitTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
543
+ Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) {
542
544
exists ( TypeMention arg | result = arg .resolveTypeAt ( path ) |
543
545
arg = getExplicitTypeArgMention ( CallExprImpl:: getFunctionPath ( this ) , apos .asTypeParam ( ) )
544
546
or
@@ -616,7 +618,7 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
616
618
pathAdj = TypePath:: singleton ( TRefTypeParameter ( ) ) and
617
619
tAdj = t
618
620
else
619
- if path .startsWith ( TRefTypeParameter ( ) , _)
621
+ if path .isCons ( TRefTypeParameter ( ) , _)
620
622
then
621
623
pathAdj = path and
622
624
tAdj = t
@@ -628,10 +630,10 @@ private module CallExprBaseMatchingInput implements MatchingInputSig {
628
630
)
629
631
else (
630
632
// adjust for implicit deref
631
- path .startsWith ( TRefTypeParameter ( ) , pathAdj ) and
633
+ path .isCons ( TRefTypeParameter ( ) , pathAdj ) and
632
634
tAdj = t
633
635
or
634
- not path .startsWith ( TRefTypeParameter ( ) , _) and
636
+ not path .isCons ( TRefTypeParameter ( ) , _) and
635
637
not ( t = TRefType ( ) and path .isEmpty ( ) ) and
636
638
pathAdj = path and
637
639
tAdj = t
@@ -674,19 +676,19 @@ private Type inferCallExprBaseType(AstNode n, TypePath path) {
674
676
if receiverType = TRefType ( )
675
677
then
676
678
path = path0 and
677
- path0 .startsWith ( TRefTypeParameter ( ) , _)
679
+ path0 .isCons ( TRefTypeParameter ( ) , _)
678
680
or
679
681
// adjust for implicit deref
680
- not path0 .startsWith ( TRefTypeParameter ( ) , _) and
682
+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
681
683
not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
682
684
path = TypePath:: cons ( TRefTypeParameter ( ) , path0 )
683
685
else (
684
- not path0 .startsWith ( TRefTypeParameter ( ) , _) and
686
+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
685
687
not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
686
688
path = path0
687
689
or
688
690
// adjust for implicit borrow
689
- path0 .startsWith ( TRefTypeParameter ( ) , path )
691
+ path0 .isCons ( TRefTypeParameter ( ) , path )
690
692
)
691
693
)
692
694
else path = path0
@@ -748,7 +750,7 @@ private module FieldExprMatchingInput implements MatchingInputSig {
748
750
class AccessPosition = DeclarationPosition ;
749
751
750
752
class Access extends FieldExpr {
751
- Type getExplicitTypeArgument ( TypeArgumentPosition apos , TypePath path ) { none ( ) }
753
+ Type getTypeArgument ( TypeArgumentPosition apos , TypePath path ) { none ( ) }
752
754
753
755
AstNode getNodeAt ( AccessPosition apos ) {
754
756
result = this .getExpr ( ) and
@@ -781,10 +783,10 @@ private module FieldExprMatchingInput implements MatchingInputSig {
781
783
if apos .isSelf ( )
782
784
then
783
785
// adjust for implicit deref
784
- path .startsWith ( TRefTypeParameter ( ) , pathAdj ) and
786
+ path .isCons ( TRefTypeParameter ( ) , pathAdj ) and
785
787
tAdj = t
786
788
or
787
- not path .startsWith ( TRefTypeParameter ( ) , _) and
789
+ not path .isCons ( TRefTypeParameter ( ) , _) and
788
790
not ( t = TRefType ( ) and path .isEmpty ( ) ) and
789
791
pathAdj = path and
790
792
tAdj = t
@@ -824,7 +826,7 @@ private Type inferFieldExprType(AstNode n, TypePath path) {
824
826
if receiverType = TRefType ( )
825
827
then
826
828
// adjust for implicit deref
827
- not path0 .startsWith ( TRefTypeParameter ( ) , _) and
829
+ not path0 .isCons ( TRefTypeParameter ( ) , _) and
828
830
not ( path0 .isEmpty ( ) and result = TRefType ( ) ) and
829
831
path = TypePath:: cons ( TRefTypeParameter ( ) , path0 )
830
832
else path = path0
@@ -846,7 +848,7 @@ private Type inferRefExprType(Expr e, TypePath path) {
846
848
or
847
849
e = re and
848
850
exists ( TypePath exprPath | result = inferType ( re .getExpr ( ) , exprPath ) |
849
- if exprPath .startsWith ( TRefTypeParameter ( ) , _)
851
+ if exprPath .isCons ( TRefTypeParameter ( ) , _)
850
852
then
851
853
// `&x` simply means `x` when `x` already has reference type
852
854
path = exprPath
@@ -975,7 +977,7 @@ private module Cached {
975
977
Stages:: TypeInference:: backref ( ) and
976
978
result = inferAnnotatedType ( n , path )
977
979
or
978
- result = inferTypeSymmetry ( n , path )
980
+ result = inferTypeEquality ( n , path )
979
981
or
980
982
result = inferImplicitSelfType ( n , path )
981
983
or
0 commit comments