@@ -15,7 +15,7 @@ abstract class TypeMention extends AstNode {
1515
1616 /** Gets the sub mention at `path`. */
1717 pragma [ nomagic]
18- TypeMention getMentionAt ( TypePath path ) {
18+ private TypeMention getMentionAt ( TypePath path ) {
1919 path .isEmpty ( ) and
2020 result = this
2121 or
@@ -49,31 +49,25 @@ class SliceTypeReprMention extends TypeMention instanceof SliceTypeRepr {
4949 override Type resolveType ( ) { result = TSliceType ( ) }
5050}
5151
52- class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
53- Path path ;
54- ItemNode resolved ;
52+ class PathTypeMention extends TypeMention , Path {
53+ TypeItemNode resolved ;
5554
56- PathTypeReprMention ( ) {
57- path = super .getPath ( ) and
58- // NOTE: This excludes unresolvable paths which is intentional as these
59- // don't add value to the type inference anyway.
60- resolved = resolvePath ( path )
61- }
55+ PathTypeMention ( ) { resolved = resolvePath ( this ) }
6256
6357 ItemNode getResolved ( ) { result = resolved }
6458
6559 pragma [ nomagic]
6660 private TypeAlias getResolvedTraitAlias ( string name ) {
6761 exists ( TraitItemNode trait |
68- trait = resolvePath ( path ) and
62+ trait = resolved and
6963 result = trait .getAnAssocItem ( ) and
7064 name = result .getName ( ) .getText ( )
7165 )
7266 }
7367
7468 pragma [ nomagic]
7569 private TypeRepr getAssocTypeArg ( string name ) {
76- result = path .getSegment ( ) .getGenericArgList ( ) .getAssocTypeArg ( name )
70+ result = this .getSegment ( ) .getGenericArgList ( ) .getAssocTypeArg ( name )
7771 }
7872
7973 /** Gets the type argument for the associated type `alias`, if any. */
@@ -86,11 +80,11 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
8680 }
8781
8882 override TypeMention getTypeArgument ( int i ) {
89- result = path .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i )
83+ result = this .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i )
9084 or
9185 // If a type argument is not given in the path, then we use the default for
9286 // the type parameter if one exists for the type.
93- not exists ( path .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i ) ) and
87+ not exists ( this .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i ) ) and
9488 result = this .resolveType ( ) .getTypeParameterDefault ( i )
9589 or
9690 // `Self` paths inside `impl` blocks have implicit type arguments that are
@@ -106,7 +100,7 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
106100 //
107101 // the `Self` return type is shorthand for `Foo<T>`.
108102 exists ( ImplItemNode node |
109- path = node .getASelfPath ( ) and
103+ this = node .getASelfPath ( ) and
110104 result = node .( ImplItemNode ) .getSelfPath ( ) .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i )
111105 )
112106 or
@@ -124,7 +118,7 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
124118 // ```
125119 // the rhs. of the type alias is a type argument to the trait.
126120 exists ( ImplItemNode impl , AssociatedTypeTypeParameter param , TypeAlias alias |
127- path = impl .getTraitPath ( ) and
121+ this = impl .getTraitPath ( ) and
128122 param .getTrait ( ) = resolved and
129123 alias = impl .getASuccessor ( param .getTypeAlias ( ) .getName ( ) .getText ( ) ) and
130124 result = alias .getTypeRepr ( ) and
@@ -142,15 +136,15 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
142136 * resulting type at `typePath`.
143137 */
144138 pragma [ nomagic]
145- Type aliasResolveTypeAt ( TypePath typePath ) {
139+ private Type aliasResolveTypeAt ( TypePath typePath ) {
146140 exists ( TypeAlias alias , TypeMention rhs | alias = resolved and rhs = alias .getTypeRepr ( ) |
147141 result = rhs .resolveTypeAt ( typePath ) and
148142 not result = pathGetTypeParameter ( alias , _)
149143 or
150144 exists ( TypeParameter tp , TypeMention arg , TypePath prefix , TypePath suffix , int i |
151145 tp = rhs .resolveTypeAt ( prefix ) and
152146 tp = pathGetTypeParameter ( alias , i ) and
153- arg = path .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i ) and
147+ arg = this .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i ) and
154148 result = arg .resolveTypeAt ( suffix ) and
155149 typePath = prefix .append ( suffix )
156150 )
@@ -169,7 +163,7 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
169163 exists ( TraitItemNode trait | trait = resolved |
170164 // If this is a `Self` path, then it resolves to the implicit `Self`
171165 // type parameter, otherwise it is a trait bound.
172- if super . getPath ( ) = trait .getASelfPath ( )
166+ if this = trait .getASelfPath ( )
173167 then result = TSelfTypeParameter ( trait )
174168 else result = TTrait ( trait )
175169 )
@@ -192,6 +186,18 @@ class PathTypeReprMention extends TypeMention instanceof PathTypeRepr {
192186 }
193187}
194188
189+ class PathTypeReprMention extends TypeMention , PathTypeRepr {
190+ private PathTypeMention path ;
191+
192+ PathTypeReprMention ( ) { path = this .getPath ( ) }
193+
194+ override TypeMention getTypeArgument ( int i ) { result = path .getTypeArgument ( i ) }
195+
196+ override Type resolveType ( ) { result = path .resolveType ( ) }
197+
198+ override Type resolveTypeAt ( TypePath typePath ) { result = path .resolveTypeAt ( typePath ) }
199+ }
200+
195201class ImplTraitTypeReprMention extends TypeMention instanceof ImplTraitTypeRepr {
196202 override TypeMention getTypeArgument ( int i ) { none ( ) }
197203
0 commit comments