@@ -5,10 +5,18 @@ private import TypeInferencePlugin as Plugin
55private import codeql.unified.internal.StaticNameBinding
66private import codeql.unified.internal.ExprPositions
77
8+ // private predicate isTypeParameterAlias(TypeAliasDeclaration alias, int i) {
9+ // exists(Unified::TypeParameter tp |
10+ // tp = alias.getTypeParameter(i) and
11+ // tp.getNameNode() = getTypeFromRef(alias.getType())
12+ // )
13+ // }
814final class TypeMention = TypeMentionImpl ;
915
1016/** An AST node that mentions a type. */
1117abstract private class TypeMentionImpl extends AstNode {
18+ abstract TypeMention resolve ( ) ;
19+
1220 /**
1321 * Gets the type mentioned at the root of this type mention.
1422 *
@@ -131,15 +139,13 @@ abstract private class ExprTypeMentionImpl extends TypeMentionImpl, Expr {
131139 pragma [ nomagic]
132140 private ClassLikeDeclaration getQualifierTypeAt ( TypePath path ) {
133141 result =
134- this .getParentQualifier ( ) .getTypeAt ( path ) .( ClassLikeDeclarationType ) .getClassLikeDeclaration ( )
142+ this .getParentQualifier ( ) .getTypeAt ( path ) .( ClassLikeDeclarationType ) .getClassLikeDeclaration ( ) and
143+ forall ( TypeParameter tp | tp = path .getElement ( _) | tp instanceof ParentTypeParameterType )
135144 }
136145
137146 pragma [ nomagic]
138- private predicate isNestedClass (
139- ClassLikeDeclaration cls , ParentTypeParameterType tp , ClassLikeDeclaration parent
140- ) {
141- cls = this .getClassLikeDeclaration ( ) and
142- tp = TParentTypeParameterType ( cls ) and
147+ private predicate isNestedClass ( ParentTypeParameterType tp , ClassLikeDeclaration parent ) {
148+ tp = TParentTypeParameterType ( this .getClassLikeDeclaration ( ) ) and
143149 parent = tp .getParent ( )
144150 }
145151
@@ -149,12 +155,9 @@ abstract private class ExprTypeMentionImpl extends TypeMentionImpl, Expr {
149155 result = this .getTypeAtImpl ( path )
150156 or
151157 // A mention of a nested type with an explicit qualifier
152- exists (
153- TypeMention qualifier , ClassLikeDeclaration cls , ParentTypeParameterType tp , TypePath prefix ,
154- TypePath suffix
155- |
158+ exists ( TypeMention qualifier , ParentTypeParameterType tp , TypePath prefix , TypePath suffix |
156159 qualifier = this .getParentQualifier ( ) and
157- this .isNestedClass ( cls , tp , this .getQualifierTypeAt ( prefix ) ) and
160+ this .isNestedClass ( tp , this .getQualifierTypeAt ( prefix ) ) and
158161 path = TypePath:: cons ( tp , suffix ) and
159162 result = qualifier .getTypeAt ( prefix .appendInverse ( suffix ) )
160163 )
@@ -188,7 +191,11 @@ abstract private class ExprTypeMentionImpl extends TypeMentionImpl, Expr {
188191 pragma [ nomagic]
189192 private ClassLikeDeclaration getImplicitEnclosingCand ( ParentTypeParameterType tp ) {
190193 not this .hasParentQualifier ( ) and
191- not this .getParent * ( ) = any ( TypeAliasDeclaration alias ) .getType ( ) and
194+ not exists ( TypeAliasDeclaration alias |
195+ this .getParent * ( ) = alias .getType ( ) //and
196+ // not this.getParent*() = any(GenericTypeExpr g).getATypeArgument() and
197+ // not this.getParent*() = any(TupleExpr t).getAnElement()
198+ ) and
192199 tp = TParentTypeParameterType ( this .getClassLikeDeclaration ( ) ) and
193200 result = this .getEnclosingClassResolved + ( )
194201 }
@@ -233,6 +240,8 @@ class AliasExprTypeMention extends ExprTypeMentionImpl {
233240 )
234241 }
235242
243+ override TypeMention resolve ( ) { result = this }
244+
236245 override TypeMention getAlias ( ) { result = alias .getType ( ) }
237246
238247 override Type getType ( ) { result = alias .getType ( ) .( TypeMention ) .getType ( ) }
@@ -350,6 +359,8 @@ private class NonAliasExprTypeMention extends ExprTypeMentionImpl {
350359 )
351360 }
352361
362+ override TypeMention resolve ( ) { result = this }
363+
353364 override TypeMention getAlias ( ) { none ( ) }
354365}
355366
@@ -382,6 +393,16 @@ private class GenericTypeExprTypeMention extends TypeMentionImpl, GenericTypeExp
382393 )
383394 }
384395
396+ override TypeMention resolve ( ) {
397+ exists ( int i |
398+ this .getBase ( ) .( AliasExprTypeMention ) .isTypeParameterAlias ( i ) and
399+ result = this .getTypeArgument ( i ) .( TypeMention ) .resolve ( )
400+ )
401+ or
402+ base = this .getBase ( ) and
403+ result = this
404+ }
405+
385406 override Type getType ( ) { result = base .getType ( ) }
386407
387408 override TypeMention getAParentQualifierCand ( ) { result = base .getAParentQualifierCand ( ) }
0 commit comments