Skip to content

Commit bbc49dc

Browse files
authored
Merge pull request #755 from calumgrant/cs/extractor-alerts
C#: Fix some LGTM alerts on the extractor
2 parents b78fcd3 + e76eb16 commit bbc49dc

File tree

24 files changed

+46
-40
lines changed

24 files changed

+46
-40
lines changed

csharp/autobuilder/Semmle.Autobuild/Project.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public Project(Autobuilder builder, string path) : base(builder, path)
3939
{
4040
projFile = builder.Actions.LoadXml(FullPath);
4141
}
42-
catch (Exception e) when (e is XmlException || e is FileNotFoundException)
42+
catch (Exception ex) when (ex is XmlException || ex is FileNotFoundException)
4343
{
4444
builder.Log(Severity.Info, $"Unable to read project file {path}.");
4545
return;

csharp/autobuilder/Semmle.Autobuild/Solution.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public Solution(Autobuilder builder, string path, bool allowProject) : base(buil
6363
{
6464
solution = SolutionFile.Parse(FullPath);
6565
}
66-
catch (Exception e) when (e is InvalidProjectFileException || e is FileNotFoundException)
66+
catch (Exception ex) when (ex is InvalidProjectFileException || ex is FileNotFoundException)
6767
{
6868
// We allow specifying projects as solutions in lgtm.yml, so model
6969
// that scenario as a solution with just that one project

csharp/extractor/Semmle.Extraction.CIL/Entities/Assembly.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger
143143
}
144144
}
145145
}
146-
catch (Exception ex)
146+
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
147147
{
148148
logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
149149
}

csharp/extractor/Semmle.Extraction.CIL/Entities/Method.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ public MemberReferenceMethod(GenericContext gc, MemberReferenceHandle handle) :
402402

403403
declType = parentMethod == null ? parent as Type : parentMethod.DeclaringType;
404404

405+
if (declType is null)
406+
throw new InternalError("Parent context of method is not a type");
407+
405408
ShortId = MakeMethodId(declType, nameLabel);
406409

407410
var typeSourceDeclaration = declType.SourceDeclaration;

csharp/extractor/Semmle.Extraction.CIL/Entities/Type.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ class GenericMethodParameter : ITypeSignature
11211121
static readonly Id excl = Id.Create("M!");
11221122
public Id MakeId(GenericContext outerGc)
11231123
{
1124-
if (innerGc != outerGc && innerGc is Method method)
1124+
if (!ReferenceEquals(innerGc, outerGc) && innerGc is Method method)
11251125
return open + method.Label.Value + close + excl + index;
11261126
return excl + index;
11271127
}

csharp/extractor/Semmle.Extraction.CSharp.Standalone/BuildAnalysis.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ void AnalyseProjectFiles(FileInfo[] projectFiles)
283283
}
284284
++succeededProjects;
285285
}
286-
catch (Exception ex)
286+
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
287287
{
288288
++failedProjects;
289289
progressMonitor.FailedProjectFile(proj.FullName, ex.Message);

csharp/extractor/Semmle.Extraction.CSharp.Standalone/NugetPackages.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ void RestoreNugetPackage(string package, IProgressMonitor pm)
183183
}
184184
}
185185
}
186-
catch (Exception e)
187-
when (e is System.ComponentModel.Win32Exception || e is FileNotFoundException)
186+
catch (Exception ex)
187+
when (ex is System.ComponentModel.Win32Exception || ex is FileNotFoundException)
188188
{
189-
pm.FailedNugetCommand(pi.FileName, pi.Arguments, e.Message);
189+
pm.FailedNugetCommand(pi.FileName, pi.Arguments, ex.Message);
190190
}
191191
}
192192

csharp/extractor/Semmle.Extraction.CSharp/Analyser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void SetReferencePaths()
9797
extractor.SetAssemblyFile(assemblyIdentity, refPath);
9898
}
9999
}
100-
catch (Exception ex)
100+
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
101101
{
102102
extractor.Message(new Message
103103
{
@@ -272,7 +272,7 @@ void DoAnalyseAssembly(PortableExecutableReference r)
272272
ReportProgress(assemblyPath, trapWriter.TrapFile, stopwatch.Elapsed, skipExtraction ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
273273
}
274274
}
275-
catch (Exception ex)
275+
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
276276
{
277277
Logger.Log(Severity.Error, " Unhandled exception analyzing {0}: {1}", r.FilePath, ex);
278278
}
@@ -354,7 +354,7 @@ void DoExtractTree(SyntaxTree tree)
354354

355355
ReportProgress(sourcePath, trapPath, stopwatch.Elapsed, excluded ? AnalysisAction.Excluded : upToDate ? AnalysisAction.UpToDate : AnalysisAction.Extracted);
356356
}
357-
catch (Exception ex)
357+
catch (Exception ex) // lgtm[cs/catch-of-all-exceptions]
358358
{
359359
extractor.Message(new Message { exception = ex, message = string.Format("Unhandled exception processing {0}: {1}", tree.FilePath, ex), severity = Severity.Error });
360360
}

csharp/extractor/Semmle.Extraction.CSharp/Entities/Modifier.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public static void ExtractModifiers(Context cx, IEntity key, ISymbol symbol)
134134
if (symbol.Kind == SymbolKind.NamedType)
135135
{
136136
INamedTypeSymbol nt = symbol as INamedTypeSymbol;
137+
if (nt is null)
138+
throw new InternalError(symbol, "Symbol kind is inconsistent with its type");
139+
137140
if (nt.TypeKind == TypeKind.Struct)
138141
{
139142
// Sadly, these properties are internal so cannot be accessed directly.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.CodeAnalysis.CSharp.Syntax;
1+
using Microsoft.CodeAnalysis.CSharp.Syntax; // lgtm[cs/similar-file]
22
using Semmle.Extraction.Kinds;
33

44
namespace Semmle.Extraction.CSharp.Entities.Statements

0 commit comments

Comments
 (0)