@@ -53,12 +53,16 @@ private predicate isParameterImpl(string name, Scope scope) {
53
53
name = "_"
54
54
}
55
55
56
+ private predicate isThisParameter ( Scope scope , Type t ) {
57
+ t = scope .getEnclosingFunction ( ) .getDeclaringType ( )
58
+ }
59
+
56
60
private newtype TParameterImpl =
57
61
TInternalParameter ( Internal:: Parameter p ) or
58
62
TUnderscore ( Scope scope ) {
59
63
exists ( VarAccess va | va .getUserPath ( ) = [ "_" , "PSItem" ] and scope = va .getEnclosingScope ( ) )
60
64
} or
61
- TThisParameter ( Scope scope ) { exists ( scope . getEnclosingFunction ( ) . getDeclaringType ( ) ) }
65
+ TThisParameter ( Scope scope ) { isThisParameter ( scope , _ ) }
62
66
63
67
private class ParameterImpl extends TParameterImpl {
64
68
abstract Location getLocation ( ) ;
@@ -88,6 +92,13 @@ private class ParameterImpl extends TParameterImpl {
88
92
abstract predicate isPipeline ( ) ;
89
93
90
94
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 ( ) ;
91
102
}
92
103
93
104
private class InternalParameter extends ParameterImpl , TInternalParameter {
@@ -122,6 +133,8 @@ private class InternalParameter extends ParameterImpl, TInternalParameter {
122
133
override predicate isPipelineByPropertyName ( ) {
123
134
this .getAnAttribute ( ) .getANamedArgument ( ) instanceof ValueFromPipelineByPropertyName
124
135
}
136
+
137
+ final override string getStaticType ( ) { result = p .getStaticType ( ) }
125
138
}
126
139
127
140
/**
@@ -158,6 +171,8 @@ private class Underscore extends ParameterImpl, TUnderscore {
158
171
final override predicate isPipelineByPropertyName ( ) { none ( ) }
159
172
160
173
final override predicate isFunctionParameter ( Function f , int i ) { f .getBody ( ) = scope and i = - 1 }
174
+
175
+ final override string getStaticType ( ) { none ( ) }
161
176
}
162
177
163
178
private class ThisParameter extends ParameterImpl , TThisParameter {
@@ -176,6 +191,13 @@ private class ThisParameter extends ParameterImpl, TThisParameter {
176
191
final override predicate isPipeline ( ) { none ( ) }
177
192
178
193
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
+ }
179
201
}
180
202
181
203
private predicate isPipelineIteratorVariable ( ParameterImpl p , ProcessBlock pb ) {
@@ -305,6 +327,8 @@ class Parameter extends AbstractLocalScopeVariable, TParameter {
305
327
predicate isPipeline ( ) { p .isPipeline ( ) }
306
328
307
329
predicate isPipelineByPropertyName ( ) { p .isPipelineByPropertyName ( ) }
330
+
331
+ string getStaticType ( ) { result = p .getStaticType ( ) }
308
332
}
309
333
310
334
class PipelineParameter extends Parameter {
0 commit comments