@@ -61,13 +61,14 @@ class PathTypeMention extends TypeMention, Path {
61
61
62
62
TypeItemNode getResolved ( ) { result = resolved }
63
63
64
+ /**
65
+ * Gets a type alias with the name `name` of the trait that this path resolves
66
+ * to, if any.
67
+ */
64
68
pragma [ nomagic]
65
69
private TypeAlias getResolvedTraitAlias ( string name ) {
66
- exists ( TraitItemNode trait |
67
- trait = resolved and
68
- result = trait .getAnAssocItem ( ) and
69
- name = result .getName ( ) .getText ( )
70
- )
70
+ result = resolved .( TraitItemNode ) .getAnAssocItem ( ) and
71
+ name = result .getName ( ) .getText ( )
71
72
}
72
73
73
74
pragma [ nomagic]
@@ -140,40 +141,18 @@ class PathTypeMention extends TypeMention, Path {
140
141
)
141
142
}
142
143
143
- override Type resolveTypeAt ( TypePath typePath ) {
144
- result = this .aliasResolveTypeAt ( typePath )
145
- or
146
- typePath .isEmpty ( ) and
147
- (
148
- result = TStruct ( resolved )
149
- or
150
- result = TEnum ( resolved )
151
- or
152
- exists ( TraitItemNode trait | trait = resolved |
153
- // If this is a `Self` path, then it resolves to the implicit `Self`
154
- // type parameter, otherwise it is a trait bound.
155
- if this = trait .getASelfPath ( )
156
- then result = TSelfTypeParameter ( trait )
157
- else result = TTrait ( trait )
158
- )
159
- or
160
- result = TTypeParamTypeParameter ( resolved )
161
- or
162
- result = TAssociatedTypeTypeParameter ( resolved )
163
- )
164
- or
144
+ /** Gets the type mention in this path for the type parameter `tp`, if any. */
145
+ pragma [ nomagic]
146
+ private TypeMention getTypeMentionForTypeParameter ( TypeParameter tp ) {
165
147
not exists ( resolved .( TypeAlias ) .getTypeRepr ( ) ) and
166
- exists ( TypeParameter tp , TypeMention arg , TypePath suffix |
167
- result = arg .resolveTypeAt ( suffix ) and
168
- typePath = TypePath:: cons ( tp , suffix )
169
- |
148
+ (
170
149
exists ( int i |
171
- arg = this .getPositionalTypeArgument ( pragma [ only_bind_into ] ( i ) ) and
150
+ result = this .getPositionalTypeArgument ( pragma [ only_bind_into ] ( i ) ) and
172
151
tp = this .resolveType ( ) .getTypeParameter ( pragma [ only_bind_into ] ( i ) )
173
152
)
174
153
or
175
154
exists ( TypeAlias alias |
176
- arg = this .getAnAssocTypeArgument ( alias ) and
155
+ result = this .getAnAssocTypeArgument ( alias ) and
177
156
tp = TAssociatedTypeTypeParameter ( alias )
178
157
)
179
158
or
@@ -195,14 +174,42 @@ class PathTypeMention extends TypeMention, Path {
195
174
param .getTrait ( ) = resolved and
196
175
name = param .getTypeAlias ( ) .getName ( ) .getText ( ) and
197
176
alias = impl .getASuccessor ( pragma [ only_bind_into ] ( name ) ) and
198
- arg = alias .getTypeRepr ( ) and
177
+ result = alias .getTypeRepr ( ) and
199
178
tp =
200
179
TAssociatedTypeTypeParameter ( resolved
201
180
.( TraitItemNode )
202
181
.getAssocItem ( pragma [ only_bind_into ] ( name ) ) )
203
182
)
204
183
)
205
184
}
185
+
186
+ override Type resolveTypeAt ( TypePath typePath ) {
187
+ result = this .aliasResolveTypeAt ( typePath )
188
+ or
189
+ typePath .isEmpty ( ) and
190
+ (
191
+ result = TStruct ( resolved )
192
+ or
193
+ result = TEnum ( resolved )
194
+ or
195
+ exists ( TraitItemNode trait | trait = resolved |
196
+ // If this is a `Self` path, then it resolves to the implicit `Self`
197
+ // type parameter, otherwise it is a trait bound.
198
+ if this = trait .getASelfPath ( )
199
+ then result = TSelfTypeParameter ( trait )
200
+ else result = TTrait ( trait )
201
+ )
202
+ or
203
+ result = TTypeParamTypeParameter ( resolved )
204
+ or
205
+ result = TAssociatedTypeTypeParameter ( resolved )
206
+ )
207
+ or
208
+ exists ( TypeParameter tp , TypePath suffix |
209
+ result = this .getTypeMentionForTypeParameter ( tp ) .resolveTypeAt ( suffix ) and
210
+ typePath = TypePath:: cons ( tp , suffix )
211
+ )
212
+ }
206
213
}
207
214
208
215
class PathTypeReprMention extends TypeMention , PathTypeRepr {
0 commit comments