@@ -53,12 +53,16 @@ private predicate isParameterImpl(string name, Scope scope) {
5353 name = "_"
5454}
5555
56+ private predicate isThisParameter ( Scope scope , Type t ) {
57+ t = scope .getEnclosingFunction ( ) .getDeclaringType ( )
58+ }
59+
5660private newtype TParameterImpl =
5761 TInternalParameter ( Internal:: Parameter p ) or
5862 TUnderscore ( Scope scope ) {
5963 exists ( VarAccess va | va .getUserPath ( ) = [ "_" , "PSItem" ] and scope = va .getEnclosingScope ( ) )
6064 } or
61- TThisParameter ( Scope scope ) { exists ( scope . getEnclosingFunction ( ) . getDeclaringType ( ) ) }
65+ TThisParameter ( Scope scope ) { isThisParameter ( scope , _ ) }
6266
6367private class ParameterImpl extends TParameterImpl {
6468 abstract Location getLocation ( ) ;
@@ -88,6 +92,13 @@ private class ParameterImpl extends TParameterImpl {
8892 abstract predicate isPipeline ( ) ;
8993
9094 abstract predicate isPipelineByPropertyName ( ) ;
95+
96+ /**
97+ * Gets the static type of this parameter.
98+ * The type of this parameter at runtime may be a subtype of this static
99+ * type.
100+ */
101+ abstract string getStaticType ( ) ;
91102}
92103
93104private class InternalParameter extends ParameterImpl , TInternalParameter {
@@ -122,6 +133,8 @@ private class InternalParameter extends ParameterImpl, TInternalParameter {
122133 override predicate isPipelineByPropertyName ( ) {
123134 this .getAnAttribute ( ) .getANamedArgument ( ) instanceof ValueFromPipelineByPropertyName
124135 }
136+
137+ final override string getStaticType ( ) { result = p .getStaticType ( ) }
125138}
126139
127140/**
@@ -158,6 +171,8 @@ private class Underscore extends ParameterImpl, TUnderscore {
158171 final override predicate isPipelineByPropertyName ( ) { none ( ) }
159172
160173 final override predicate isFunctionParameter ( Function f , int i ) { f .getBody ( ) = scope and i = - 1 }
174+
175+ final override string getStaticType ( ) { none ( ) }
161176}
162177
163178private class ThisParameter extends ParameterImpl , TThisParameter {
@@ -176,6 +191,13 @@ private class ThisParameter extends ParameterImpl, TThisParameter {
176191 final override predicate isPipeline ( ) { none ( ) }
177192
178193 final override predicate isPipelineByPropertyName ( ) { none ( ) }
194+
195+ final override string getStaticType ( ) {
196+ exists ( Type t |
197+ isThisParameter ( scope , t ) and
198+ result = t .getName ( )
199+ )
200+ }
179201}
180202
181203private predicate isPipelineIteratorVariable ( ParameterImpl p , ProcessBlock pb ) {
@@ -305,6 +327,8 @@ class Parameter extends AbstractLocalScopeVariable, TParameter {
305327 predicate isPipeline ( ) { p .isPipeline ( ) }
306328
307329 predicate isPipelineByPropertyName ( ) { p .isPipelineByPropertyName ( ) }
330+
331+ string getStaticType ( ) { result = p .getStaticType ( ) }
308332}
309333
310334class PipelineParameter extends Parameter {
0 commit comments