@@ -1657,22 +1657,41 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
16571657
16581658 /**
16591659 * Gets the switch statement or expression whose pattern declares this identifier, if any.
1660- *
1661- * Note this only applies to a direct binding pattern, such as `case T t`, not a record pattern.
16621660 */
1663- StmtParent getAssociatedSwitch ( ) { result = this .getParent ( ) .( PatternCase ) .getParent ( ) }
1661+ StmtParent getAssociatedSwitch ( ) {
1662+ exists ( PatternCase pc |
1663+ pc = result .( SwitchStmt ) .getAPatternCase ( )
1664+ or
1665+ pc = result .( SwitchExpr ) .getAPatternCase ( )
1666+ |
1667+ this = pc .getPattern ( ) .getAChildExpr * ( )
1668+ )
1669+ }
16641670
16651671 /** Holds if this is a declaration stemming from a pattern switch case. */
16661672 predicate hasAssociatedSwitch ( ) { exists ( this .getAssociatedSwitch ( ) ) }
16671673
1674+ /**
1675+ * Gets the instanceof expression whose pattern declares this identifier, if any.
1676+ */
1677+ InstanceOfExpr getAssociatedInstanceOfExpr ( ) {
1678+ result .getPattern ( ) .getAChildExpr * ( ) = this
1679+ }
1680+
1681+ /** Holds f this is a declaration stemming from a pattern instanceof expression. */
1682+ predicate hasAssociatedInstanceOfExpr ( ) {
1683+ exists ( this .getAssociatedInstanceOfExpr ( ) )
1684+ }
1685+
16681686 /** Gets the initializer expression of this local variable declaration expression, if any. */
16691687 Expr getInit ( ) { result .isNthChildOf ( this , 0 ) }
16701688
16711689 /** Holds if this variable declaration implicitly initializes the variable. */
16721690 predicate hasImplicitInit ( ) {
16731691 exists ( CatchClause cc | cc .getVariable ( ) = this ) or
16741692 exists ( EnhancedForStmt efs | efs .getVariable ( ) = this ) or
1675- this .hasAssociatedSwitch ( )
1693+ this .hasAssociatedSwitch ( ) or
1694+ this .hasAssociatedInstanceOfExpr ( )
16761695 }
16771696
16781697 /** Gets a printable representation of this expression. */
0 commit comments