Skip to content

Commit 86b91ce

Browse files
authored
Merge pull request #4111 from tamasvajk/feature/nullability-extraction
C#: Fix nullability warning in Semmle.Extraction
2 parents ea77828 + b9e3b32 commit 86b91ce

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

csharp/extractor/Semmle.Extraction/CommentProcessing.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void AddComment(ICommentLine comment)
3535

3636
class LocationComparer : IComparer<Location>
3737
{
38-
public int Compare(Location l1, Location l2) => CommentProcessor.Compare(l1, l2);
38+
public int Compare(Location? l1, Location? l2) => CommentProcessor.Compare(l1, l2);
3939
}
4040

4141
/// <summary>
@@ -44,8 +44,12 @@ class LocationComparer : IComparer<Location>
4444
/// <param name="l1">First location</param>
4545
/// <param name="l2">Second location</param>
4646
/// <returns>&lt;0 if l1 before l2, &gt;0 if l1 after l2, else 0.</returns>
47-
static int Compare(Location l1, Location l2)
47+
static int Compare(Location? l1, Location? l2)
4848
{
49+
if (object.ReferenceEquals(l1, l2)) return 0;
50+
if (l1 == null) return -1;
51+
if (l2 == null) return 1;
52+
4953
int diff = l1.SourceTree == l2.SourceTree ? 0 : l1.SourceTree.FilePath.CompareTo(l2.SourceTree.FilePath);
5054
if (diff != 0) return diff;
5155
diff = l1.SourceSpan.Start - l2.SourceSpan.Start;
@@ -243,7 +247,7 @@ CommentBindingCallback cb
243247
/// Process comments up until nextElement.
244248
/// Group comments into blocks, and associate blocks with elements.
245249
/// </summary>
246-
///
250+
///
247251
/// <param name="commentEnumerator">Enumerator for all comments in the program.</param>
248252
/// <param name="nextElement">The next element in the list.</param>
249253
/// <param name="elementStack">A stack of nested program elements.</param>
@@ -261,7 +265,7 @@ CommentBindingCallback cb
261265
// Iterate comments until the commentEnumerator has gone past nextElement
262266
while (nextElement == null || Compare(commentEnumerator.Current.Value.Location, nextElement.Value.Key) < 0)
263267
{
264-
if(block is null)
268+
if (block is null)
265269
block = new CommentBlock(commentEnumerator.Current.Value);
266270

267271
if (!block.CombinesWith(commentEnumerator.Current.Value))
@@ -284,7 +288,7 @@ CommentBindingCallback cb
284288
}
285289
}
286290

287-
if(!(block is null))
291+
if (!(block is null))
288292
GenerateBindings(block, elementStack, nextElement, cb);
289293

290294
return true;

0 commit comments

Comments
 (0)