@@ -281,7 +281,7 @@ class Pair extends Expr instanceof PairImpl {
281281}
282282
283283/**
284- * A list of exception types in a rescue clause. For example, the exception list
284+ * A disjunctive exception pattern match in a rescue clause. For example, the exception list
285285 * `FirstError, SecondError` in:
286286 * ```rb
287287 * begin
@@ -290,7 +290,6 @@ class Pair extends Expr instanceof PairImpl {
290290 * handle_error(e)
291291 * end
292292 * ```
293- * This node is only present when there are two or more exceptions in the list.
294293 */
295294class ExceptionList extends Expr , TExceptionList {
296295 private Ruby:: Exceptions g ;
@@ -327,16 +326,18 @@ class RescueClause extends Expr, TRescueClause {
327326
328327 final override string getAPrimaryQlClass ( ) { result = "RescueClause" }
329328
329+ /** Gets the exception list pattern when there are multiple exception expressions. */
330+ private ExceptionList getExceptions ( ) { result = TExceptionList ( g .getExceptions ( ) ) }
331+
330332 /**
331333 * Gets the `n`th exception to match, if any. For example `FirstError` or `SecondError` in:
332334 * ```rb
333335 * begin
334- * do_something
336+ * do_something
335337 * rescue FirstError, SecondError => e
336338 * handle_error(e)
337339 * end
338340 * ```
339- * When there are two or more exceptions, use `getExceptions()` to get the `ExceptionList` node.
340341 */
341342 final Expr getException ( int n ) {
342343 // 0 or 1 exception: no ExceptionList node, access directly
@@ -351,7 +352,7 @@ class RescueClause extends Expr, TRescueClause {
351352 * Gets an exception to match, if any. For example `FirstError` or `SecondError` in:
352353 * ```rb
353354 * begin
354- * do_something
355+ * do_something
355356 * rescue FirstError, SecondError => e
356357 * handle_error(e)
357358 * end
@@ -360,24 +361,34 @@ class RescueClause extends Expr, TRescueClause {
360361 final Expr getAnException ( ) { result = this .getException ( _) }
361362
362363 /**
363- * Gets the exception list node when there are two or more exceptions to match. For example,
364- * the exception list `FirstError, SecondError` in:
364+ * Gets the exception pattern to match, if any.
365+ *
366+ * This is either a single exception expression, or an `ExceptionList`
367+ * representing a disjunctive match of multiple exceptions when there are two
368+ * or more exceptions expressions.
369+ *
370+ * For example, in the following code, the exception pattern is the
371+ * exception list `FirstError, SecondError`:
365372 * ```rb
366373 * begin
367- * do_something
374+ * do_something
368375 * rescue FirstError, SecondError => e
369376 * handle_error(e)
370377 * end
371378 * ```
372379 */
373- final ExceptionList getExceptions ( ) { result = TExceptionList ( g .getExceptions ( ) ) }
380+ final Expr getPattern ( ) {
381+ result = this .getExceptions ( )
382+ or
383+ not exists ( this .getExceptions ( ) ) and result = this .getAnException ( )
384+ }
374385
375386 /**
376387 * Gets the variable to which to assign the matched exception, if any.
377388 * For example `err` in:
378389 * ```rb
379390 * begin
380- * do_something
391+ * do_something
381392 * rescue StandardError => err
382393 * handle_error(err)
383394 * end
@@ -395,13 +406,7 @@ class RescueClause extends Expr, TRescueClause {
395406 final override AstNode getAChild ( string pred ) {
396407 result = super .getAChild ( pred )
397408 or
398- // For 0 or 1 exceptions, exceptions are direct children
399- not exists ( this .getExceptions ( ) ) and
400- pred = "getException" and
401- result = this .getException ( _)
402- or
403- // For 2+ exceptions, the ExceptionList node is the direct child
404- pred = "getExceptions" and result = this .getExceptions ( )
409+ pred = "getPattern" and result = this .getPattern ( )
405410 or
406411 pred = "getVariableExpr" and result = this .getVariableExpr ( )
407412 or
0 commit comments