Skip to content

Extract TypeMention for catch (Exception) clauses#22031

Merged
aschackmull merged 3 commits into
mainfrom
copilot/tweak-csharp-extractor
Jun 22, 2026
Merged

Extract TypeMention for catch (Exception) clauses#22031
aschackmull merged 3 commits into
mainfrom
copilot/tweak-csharp-extractor

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Specific C# catch clauses are already distinguished from general catch {} clauses via catch_type, but catch (Exception) did not extract the exception type as a TypeMention unless a variable was also declared. This change makes catch (Exception) extract its TypeMention directly under the catch clause, aligning it with the typed catch shape already exposed for catch (Exception e).

  • Extractor behavior

    • Emit a TypeMention from Catch when the clause is of the form catch (T) and has no variable declaration.
    • Keep existing behavior unchanged for:
      • catch {} → general catch, no type mention
      • catch (T e) → specific catch, type mention remains attached via the variable declaration
  • AST shape

    • catch (T) now contributes:
      • catch_type(..., T, specific)
      • TypeMention(T) as a direct child of the catch clause
    • This gives the QL side a consistent typed representation for both forms of specific catch clauses.
  • Regression coverage

    • Extend the C# type-mention regression corpus with a catch (Exception) example.
    • Update the expected output to include the extracted Exception type mention.
try
{
}
catch (Exception)
{
}

Expected extractor effect: Exception is now present as a TypeMention child of the catch clause.

@aschackmull aschackmull marked this pull request as ready for review June 22, 2026 11:24
@aschackmull aschackmull requested a review from a team as a code owner June 22, 2026 11:24
Copilot AI review requested due to automatic review settings June 22, 2026 11:24
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Jun 22, 2026
@aschackmull aschackmull merged commit 48b0cbc into main Jun 22, 2026
18 checks passed
@aschackmull aschackmull deleted the copilot/tweak-csharp-extractor branch June 22, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the C# extractor to emit a TypeMention directly under a Catch clause for typed catch clauses without a variable declaration (e.g., catch (Exception)), aligning the AST shape with existing typed catches that declare a variable (e.g., catch (Exception e)).

Changes:

  • Update Catch extraction to create a TypeMention for catch (T) clauses that omit a variable identifier.
  • Extend the type-mention regression test corpus to include catch (Exception) and update expected results.
  • Update PrintAst expectations to reflect the new TypeMention child under SpecificCatchClause for catch (T) without a variable.
Show a summary per file
File Description
csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs Emits a TypeMention under the catch clause for catch (T) with no variable.
csharp/ql/test/library-tests/regressions/Program.cs Adds a catch (Exception) example to exercise the new extraction behavior.
csharp/ql/test/library-tests/regressions/TypeMentions.expected Updates expected TypeMention results to include the new void return type and Exception in catch (Exception).
csharp/ql/test/library-tests/csharp6/PrintAst.expected Updates AST print expectations so catch (T) now has a TypeMention child.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C# no-change-note-required This PR does not need a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants