Extract TypeMention for catch (Exception) clauses#22031
Merged
Conversation
Copilot created this pull request from a session on behalf of
aschackmull
June 22, 2026 10:33
View session
aschackmull
approved these changes
Jun 22, 2026
hvitved
approved these changes
Jun 22, 2026
Contributor
There was a problem hiding this comment.
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
Catchextraction to create aTypeMentionforcatch (T)clauses that omit a variable identifier. - Extend the type-mention regression test corpus to include
catch (Exception)and update expected results. - Update
PrintAstexpectations to reflect the newTypeMentionchild underSpecificCatchClauseforcatch (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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Specific C# catch clauses are already distinguished from general
catch {}clauses viacatch_type, butcatch (Exception)did not extract the exception type as aTypeMentionunless a variable was also declared. This change makescatch (Exception)extract itsTypeMentiondirectly under the catch clause, aligning it with the typed catch shape already exposed forcatch (Exception e).Extractor behavior
TypeMentionfromCatchwhen the clause is of the formcatch (T)and has no variable declaration.catch {}→ general catch, no type mentioncatch (T e)→ specific catch, type mention remains attached via the variable declarationAST shape
catch (T)now contributes:catch_type(..., T, specific)TypeMention(T)as a direct child of the catch clauseRegression coverage
catch (Exception)example.Exceptiontype mention.Expected extractor effect:
Exceptionis now present as aTypeMentionchild of the catch clause.