@@ -273,11 +273,17 @@ module AssignableInternal {
273
273
def = TPatternDefinition ( result )
274
274
}
275
275
276
- /** A local variable declaration at the top-level of a pattern . */
277
- class TopLevelPatternDecl extends LocalVariableDeclExpr {
276
+ /** A pattern containing a local variable declaration . */
277
+ class LocalVariablePatternDecl extends LocalVariableDeclExpr {
278
278
private PatternMatch pm ;
279
279
280
- TopLevelPatternDecl ( ) { this = pm .getPattern ( ) .( BindingPatternExpr ) .getVariableDeclExpr ( ) }
280
+ LocalVariablePatternDecl ( ) {
281
+ exists ( BindingPatternExpr bpe |
282
+ this = bpe .getVariableDeclExpr ( ) and pm = bpe .getPatternMatch ( )
283
+ )
284
+ }
285
+
286
+ predicate isTopLevel ( ) { this = pm .getPattern ( ) .( BindingPatternExpr ) .getVariableDeclExpr ( ) }
281
287
282
288
PatternMatch getMatch ( ) { result = pm }
283
289
}
@@ -297,7 +303,7 @@ module AssignableInternal {
297
303
TLocalVariableDefinition ( LocalVariableDeclExpr lvde ) {
298
304
not lvde .hasInitializer ( ) and
299
305
not exists ( getTupleSource ( TTupleAssignmentDefinition ( _, lvde ) ) ) and
300
- not lvde instanceof TopLevelPatternDecl and
306
+ not lvde instanceof LocalVariablePatternDecl and
301
307
not lvde .isOutArgument ( )
302
308
} or
303
309
TImplicitParameterDefinition ( Parameter p ) {
@@ -309,7 +315,7 @@ module AssignableInternal {
309
315
)
310
316
} or
311
317
TAddressOfDefinition ( AddressOfExpr aoe ) or
312
- TPatternDefinition ( TopLevelPatternDecl tlpd )
318
+ TPatternDefinition ( LocalVariablePatternDecl lvpd )
313
319
314
320
/**
315
321
* Gets the source expression assigned in tuple definition `def`, if any.
@@ -699,22 +705,25 @@ module AssignableDefinitions {
699
705
}
700
706
701
707
/**
702
- * A local variable definition in a pattern, for example `x is int i`.
708
+ * A local variable definition in a pattern, for example `int i` in ` x is int i`.
703
709
*/
704
710
class PatternDefinition extends AssignableDefinition , TPatternDefinition {
705
- TopLevelPatternDecl tlpd ;
711
+ LocalVariablePatternDecl lvpd ;
706
712
707
- PatternDefinition ( ) { this = TPatternDefinition ( tlpd ) }
713
+ PatternDefinition ( ) { this = TPatternDefinition ( lvpd ) }
708
714
709
715
/** Gets the element matches against this pattern. */
710
- PatternMatch getMatch ( ) { result = tlpd .getMatch ( ) }
716
+ PatternMatch getMatch ( ) { result = lvpd .getMatch ( ) }
711
717
712
718
/** Gets the underlying local variable declaration. */
713
- LocalVariableDeclExpr getDeclaration ( ) { result = tlpd }
719
+ LocalVariableDeclExpr getDeclaration ( ) { result = lvpd }
714
720
715
- override Expr getSource ( ) { result = this .getMatch ( ) .getExpr ( ) }
721
+ override Expr getSource ( ) { this . isTopLevel ( ) and result = this .getMatch ( ) .getExpr ( ) }
716
722
717
723
override string toString ( ) { result = this .getDeclaration ( ) .toString ( ) }
724
+
725
+ /** Holds if the local variable definition is at the top level of the pattern. */
726
+ predicate isTopLevel ( ) { lvpd .isTopLevel ( ) }
718
727
}
719
728
720
729
/**
0 commit comments