Skip to content

C# extractor: extract catch(ExceptionType) type as TypeAccess instead of TypeMention#22037

Merged
aschackmull merged 1 commit into
mainfrom
copilot/update-csharp-extractor-catch-clause
Jun 23, 2026
Merged

C# extractor: extract catch(ExceptionType) type as TypeAccess instead of TypeMention#22037
aschackmull merged 1 commit into
mainfrom
copilot/update-csharp-extractor-catch-clause

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

For catch(Exception) clauses (type present, no variable), the exception type was extracted as a TypeMention rather than a TypeAccess. Changing this makes it an expression, and makes it easier to include in the CFG (will be done in another PR).

Changes

  • Catch.cs: For case 2 (catch(T) without variable), replace TypeMention.Create(...) with Expression.Create(...), producing a TypeAccess at child 0.
  • Stmt.qll: Add getTypeAccess() predicate to SpecificCatchClause, returning the TypeAccess at child 0 when no VariableDeclExpr is present.
  • ControlFlowGraph.qll: Add not skipControlFlow(result) to getStmtChild0 — consistent with getExprChild0 — so the new TypeAccess (a ControlFlowElement) doesn't pollute the CFG.

The three catch variants for reference:

catch { }                  // 1. unchanged
catch (Exception) { }      // 2. now extracts Exception as TypeAccess (was TypeMention)
catch (Exception e) { }    // 3. unchanged (VariableDeclExpr at child 0)

Copilot AI changed the title C# extractor: extract catch(Ex) type as TypeAccess instead of TypeMention C# extractor: extract catch(ExceptionType) type as TypeAccess instead of TypeMention Jun 23, 2026
Copilot AI requested a review from aschackmull June 23, 2026 09:03
@aschackmull aschackmull force-pushed the copilot/update-csharp-extractor-catch-clause branch from 5310acc to b254aa7 Compare June 23, 2026 11:56
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Jun 23, 2026
@aschackmull aschackmull marked this pull request as ready for review June 23, 2026 12:00
@aschackmull aschackmull requested a review from a team as a code owner June 23, 2026 12:00
Copilot AI review requested due to automatic review settings June 23, 2026 12:00

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

Updates C# catch-clause extraction so catch (T) (type present, no variable) produces a TypeAccess expression instead of a TypeMention, enabling downstream control-flow/CFG work while preserving existing catch variants.

Changes:

  • Extract catch (T)’s type as an Expression (yielding a TypeAccess at child 0) in the C# extractor.
  • Add a SpecificCatchClause.getTypeAccess() accessor in the C# QL library for the no-variable case.
  • Adjust CFG child selection to avoid including skipped control-flow nodes (including the newly introduced TypeAccess) as statement children.
Show a summary per file
File Description
csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs Switches catch (T) extraction from TypeMention to Expression to create a TypeAccess child.
csharp/ql/lib/semmle/code/csharp/Stmt.qll Adds getTypeAccess() on SpecificCatchClause for catch (T) without a variable.
csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraph.qll Updates statement-child selection to respect skipControlFlow, preventing TypeAccess from being pulled into the CFG.
csharp/ql/test/library-tests/csharp6/PrintAst.expected Updates expected AST output to reflect the new TypeAccess node structure.

Copilot's findings

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

@aschackmull aschackmull merged commit cfbf4a3 into main Jun 23, 2026
27 checks passed
@aschackmull aschackmull deleted the copilot/update-csharp-extractor-catch-clause branch June 23, 2026 12:21
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