Skip to content

Commit 089bb33

Browse files
authored
Merge pull request #6773 from tamasvajk/fix/global-stmt-library
C#: Handle invalid code gracefully: global statements in library
2 parents 8dcf792 + e170717 commit 089bb33

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

csharp/extractor/Semmle.Extraction.CSharp/Populators/CompilationUnitVisitor.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,15 @@ private void ExtractGlobalStatements(CompilationUnitSyntax compilationUnit)
5959
return;
6060
}
6161

62-
var entryPoint = Cx.Compilation.GetEntryPoint(System.Threading.CancellationToken.None)!;
62+
var entryPoint = Cx.Compilation.GetEntryPoint(System.Threading.CancellationToken.None);
6363
var entryMethod = Method.Create(Cx, entryPoint);
64+
if (entryMethod is null)
65+
{
66+
Cx.ExtractionError("No entry method found. Skipping the extraction of global statements.",
67+
null, Cx.CreateLocation(globalStatements[0].GetLocation()), null, Severity.Info);
68+
return;
69+
}
70+
6471
var block = GlobalStatementsBlock.Create(Cx, entryMethod);
6572

6673
for (var i = 0; i < globalStatements.Count; i++)

0 commit comments

Comments
 (0)