@@ -53,11 +53,31 @@ class TypeReprMention extends TypeMention, TypeRepr {
53
53
or
54
54
result = this .( PathTypeRepr ) .getPath ( ) .( PathMention ) .resolveType ( )
55
55
}
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 ( )
56
68
}
57
69
58
- class PathMention extends TypeMention , Path {
70
+ abstract class PathMention extends TypeMention , Path {
59
71
override TypeMention getTypeArgument ( int i ) {
60
72
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 )
61
81
or
62
82
// `Self` paths inside `impl` blocks have implicit type arguments that are
63
83
// the type parameters of the `impl` block. For example, in
@@ -98,6 +118,33 @@ class PathMention extends TypeMention, Path {
98
118
}
99
119
}
100
120
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
+
101
148
// Used to represent implicit `Self` type arguments in traits and `impl` blocks,
102
149
// see `PathMention` for details.
103
150
class TypeParamMention extends TypeMention , TypeParam {
0 commit comments