@@ -53,11 +53,31 @@ class TypeReprMention extends TypeMention, TypeRepr {
5353 or
5454 result = this .( PathTypeRepr ) .getPath ( ) .( PathMention ) .resolveType ( )
5555 }
56+
57+ override Type resolveTypeAt ( TypePath path ) {
58+ result = this .( PathTypeRepr ) .getPath ( ) .( PathMention ) .resolveTypeAt ( path )
59+ or
60+ not exists ( this .( PathTypeRepr ) .getPath ( ) ) and
61+ result = super .resolveTypeAt ( path )
62+ }
63+ }
64+
65+ /** Holds if `path` resolves to the type alias `alias` with the definition `rhs`. */
66+ private predicate resolvePathAlias ( Path path , TypeAlias alias , TypeReprMention rhs ) {
67+ alias = resolvePath ( path ) and rhs = alias .getTypeRepr ( )
5668}
5769
58- class PathMention extends TypeMention , Path {
70+ abstract class PathMention extends TypeMention , Path {
5971 override TypeMention getTypeArgument ( int i ) {
6072 result = this .getSegment ( ) .getGenericArgList ( ) .getTypeArg ( i )
73+ }
74+ }
75+
76+ class NonAliasPathMention extends PathMention {
77+ NonAliasPathMention ( ) { not resolvePathAlias ( this , _, _) }
78+
79+ override TypeMention getTypeArgument ( int i ) {
80+ result = super .getTypeArgument ( i )
6181 or
6282 // `Self` paths inside `impl` blocks have implicit type arguments that are
6383 // the type parameters of the `impl` block. For example, in
@@ -98,6 +118,33 @@ class PathMention extends TypeMention, Path {
98118 }
99119}
100120
121+ class AliasPathMention extends PathMention {
122+ TypeAlias alias ;
123+ TypeReprMention rhs ;
124+
125+ AliasPathMention ( ) { resolvePathAlias ( this , alias , rhs ) }
126+
127+ /** Get the `i`th type parameter of the alias itself. */
128+ private TypeParameter getTypeParameter ( int i ) {
129+ result = TTypeParamTypeParameter ( alias .getGenericParamList ( ) .getTypeParam ( i ) )
130+ }
131+
132+ override Type resolveType ( ) { result = rhs .resolveType ( ) }
133+
134+ override Type resolveTypeAt ( TypePath path ) {
135+ result = rhs .resolveTypeAt ( path ) and
136+ not result = this .getTypeParameter ( _)
137+ or
138+ exists ( TypeParameter tp , TypeMention arg , TypePath prefix , TypePath suffix , int i |
139+ tp = rhs .resolveTypeAt ( prefix ) and
140+ tp = this .getTypeParameter ( i ) and
141+ arg = this .getTypeArgument ( i ) and
142+ result = arg .resolveTypeAt ( suffix ) and
143+ path = prefix .append ( suffix )
144+ )
145+ }
146+ }
147+
101148// Used to represent implicit `Self` type arguments in traits and `impl` blocks,
102149// see `PathMention` for details.
103150class TypeParamMention extends TypeMention , TypeParam {
0 commit comments