@@ -277,15 +277,28 @@ module AssignableInternal {
277277 def = TParameterDefaultDefinition ( _, result )
278278 }
279279
280- /** A local variable declaration at the top-level of a pattern . */
281- class TopLevelPatternDecl extends LocalVariableDeclExpr {
280+ /** A pattern containing a local variable declaration . */
281+ class LocalVariablePatternDecl extends LocalVariableDeclExpr {
282282 private PatternMatch pm ;
283283
284- TopLevelPatternDecl ( ) { this = pm .getPattern ( ) .( BindingPatternExpr ) .getVariableDeclExpr ( ) }
284+ LocalVariablePatternDecl ( ) {
285+ exists ( BindingPatternExpr bpe |
286+ this = bpe .getVariableDeclExpr ( ) and pm = bpe .getPatternMatch ( )
287+ )
288+ }
289+
290+ /** Holds if the local variable definition is at the top level of the pattern. */
291+ predicate isTopLevel ( ) { this = pm .getPattern ( ) .( BindingPatternExpr ) .getVariableDeclExpr ( ) }
285292
293+ /** Gets the pattern match that this local variable declaration (pattern) belongs to. */
286294 PatternMatch getMatch ( ) { result = pm }
287295 }
288296
297+ /** A local variable declaration at the top-level of a pattern. */
298+ class TopLevelPatternDecl extends LocalVariablePatternDecl {
299+ TopLevelPatternDecl ( ) { this .isTopLevel ( ) }
300+ }
301+
289302 cached
290303 private module Cached {
291304 cached
@@ -305,7 +318,7 @@ module AssignableInternal {
305318 TLocalVariableDefinition ( LocalVariableDeclExpr lvde ) {
306319 not lvde .hasInitializer ( ) and
307320 not exists ( getTupleSource ( TTupleAssignmentDefinition ( _, lvde ) ) ) and
308- not lvde instanceof TopLevelPatternDecl and
321+ not lvde instanceof LocalVariablePatternDecl and
309322 not lvde .isOutArgument ( )
310323 } or
311324 TImplicitParameterDefinition ( Parameter p ) {
@@ -324,7 +337,7 @@ module AssignableInternal {
324337 default = p .getDefaultValue ( )
325338 } or
326339 TAddressOfDefinition ( AddressOfExpr aoe ) or
327- TPatternDefinition ( TopLevelPatternDecl tlpd ) or
340+ TPatternDefinition ( LocalVariablePatternDecl lvpd ) or
328341 TAssignOperationDefinition ( AssignOperation ao ) {
329342 ao instanceof AssignCallExpr and not ao instanceof CompoundAssignmentOperatorCall
330343 or
@@ -737,24 +750,31 @@ module AssignableDefinitions {
737750 }
738751
739752 /**
740- * A local variable definition in a pattern, for example `x is int i`.
753+ * A local variable definition in a pattern, for example `int i` in ` x is int i`.
741754 */
742755 class PatternDefinition extends AssignableDefinition , TPatternDefinition {
743- TopLevelPatternDecl tlpd ;
756+ LocalVariablePatternDecl lvpd ;
744757
745- PatternDefinition ( ) { this = TPatternDefinition ( tlpd ) }
758+ PatternDefinition ( ) { this = TPatternDefinition ( lvpd ) }
746759
747760 /** Gets the element matches against this pattern. */
748- PatternMatch getMatch ( ) { result = tlpd .getMatch ( ) }
761+ PatternMatch getMatch ( ) { result = lvpd .getMatch ( ) }
749762
750763 /** Gets the underlying local variable declaration. */
751- LocalVariableDeclExpr getDeclaration ( ) { result = tlpd }
752-
753- override Expr getSource ( ) { result = this .getMatch ( ) .getExpr ( ) }
764+ LocalVariableDeclExpr getDeclaration ( ) { result = lvpd }
754765
755766 override string toString ( ) { result = this .getDeclaration ( ) .toString ( ) }
756767 }
757768
769+ /**
770+ * A local variable definition at the top level of a pattern.
771+ */
772+ class TopLevelPatternDefinition extends PatternDefinition {
773+ TopLevelPatternDefinition ( ) { lvpd .isTopLevel ( ) }
774+
775+ override Expr getSource ( ) { result = this .getMatch ( ) .getExpr ( ) }
776+ }
777+
758778 /**
759779 * An initializer definition for a field or a property, for example
760780 * line 2 in
0 commit comments