Skip to content

Commit 48b0cbc

Browse files
authored
Merge pull request #22031 from github/copilot/tweak-csharp-extractor
Extract `TypeMention` for `catch (Exception)` clauses
2 parents 03187ae + ac7ed06 commit 48b0cbc

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ protected override void PopulateStatement(TextWriter trapFile)
2323
}
2424
else if (isSpecificCatchClause) // A catch clause of the form 'catch(Ex) { ... }'
2525
{
26-
trapFile.catch_type(this, Type.Create(Context, Context.GetType(Stmt.Declaration!.Type)).TypeRef, true);
26+
var type = Type.Create(Context, Context.GetType(Stmt.Declaration!.Type));
27+
trapFile.catch_type(this, type.TypeRef, true);
28+
TypeMention.Create(Context, Stmt.Declaration!.Type, this, type);
2729
}
2830
else // A catch clause of the form 'catch { ... }'
2931
{

csharp/ql/test/library-tests/csharp6/PrintAst.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ csharp6.cs:
101101
# 32| 0: [IntLiteral] 2
102102
# 32| 0: [IntLiteral] 1
103103
# 34| 1: [SpecificCatchClause] catch (...) {...}
104+
# 34| 0: [TypeMention] IndexOutOfRangeException
104105
# 35| 1: [BlockStmt] {...}
105106
# 34| 2: [EQExpr] ... == ...
106107
# 34| 0: [PropertyCall] access to property Value

csharp/ql/test/library-tests/regressions/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,16 @@ class C3<T> : C2<C4<T>> { }
194194
class C4<T> : C2<C3<T>> { }
195195

196196
class C5 : C4<C5> { }
197+
198+
class CatchTypeMentions
199+
{
200+
void F()
201+
{
202+
try
203+
{
204+
}
205+
catch (Exception)
206+
{
207+
}
208+
}
209+
}

csharp/ql/test/library-tests/regressions/TypeMentions.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,5 @@
100100
| Program.cs:194:21:194:21 | T |
101101
| Program.cs:196:12:196:17 | C4<C5> |
102102
| Program.cs:196:15:196:16 | C5 |
103+
| Program.cs:200:5:200:8 | Void |
104+
| Program.cs:205:16:205:24 | Exception |

0 commit comments

Comments
 (0)