diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs index f3a10f4ef68..30669aae78f 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/Statements/Catch.cs @@ -23,7 +23,9 @@ namespace Semmle.Extraction.CSharp.Entities.Statements } else if (isSpecificCatchClause) // A catch clause of the form 'catch(Ex) { ... }' { - trapFile.catch_type(this, Type.Create(Context, Context.GetType(Stmt.Declaration!.Type)).TypeRef, true); + var type = Type.Create(Context, Context.GetType(Stmt.Declaration!.Type)); + trapFile.catch_type(this, type.TypeRef, true); + TypeMention.Create(Context, Stmt.Declaration!.Type, this, type); } else // A catch clause of the form 'catch { ... }' { diff --git a/csharp/ql/test/library-tests/csharp6/PrintAst.expected b/csharp/ql/test/library-tests/csharp6/PrintAst.expected index 78747650190..140a63c941c 100644 --- a/csharp/ql/test/library-tests/csharp6/PrintAst.expected +++ b/csharp/ql/test/library-tests/csharp6/PrintAst.expected @@ -101,6 +101,7 @@ csharp6.cs: # 32| 0: [IntLiteral] 2 # 32| 0: [IntLiteral] 1 # 34| 1: [SpecificCatchClause] catch (...) {...} +# 34| 0: [TypeMention] IndexOutOfRangeException # 35| 1: [BlockStmt] {...} # 34| 2: [EQExpr] ... == ... # 34| 0: [PropertyCall] access to property Value diff --git a/csharp/ql/test/library-tests/regressions/Program.cs b/csharp/ql/test/library-tests/regressions/Program.cs index dd73876f1a3..74bcf994681 100644 --- a/csharp/ql/test/library-tests/regressions/Program.cs +++ b/csharp/ql/test/library-tests/regressions/Program.cs @@ -194,3 +194,16 @@ class C3 : C2> { } class C4 : C2> { } class C5 : C4 { } + +class CatchTypeMentions +{ + void F() + { + try + { + } + catch (Exception) + { + } + } +} diff --git a/csharp/ql/test/library-tests/regressions/TypeMentions.expected b/csharp/ql/test/library-tests/regressions/TypeMentions.expected index 6c9e25efd0a..c5aad0df1bd 100644 --- a/csharp/ql/test/library-tests/regressions/TypeMentions.expected +++ b/csharp/ql/test/library-tests/regressions/TypeMentions.expected @@ -100,3 +100,5 @@ | Program.cs:194:21:194:21 | T | | Program.cs:196:12:196:17 | C4 | | Program.cs:196:15:196:16 | C5 | +| Program.cs:200:5:200:8 | Void | +| Program.cs:205:16:205:24 | Exception |