Skip to content

Commit 7b1f9f1

Browse files
committed
C#: Adjust the empty location to point to the unique generated empty location.
1 parent 53fb4b0 commit 7b1f9f1

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

csharp/ql/lib/semmle/code/csharp/Location.qll

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,29 @@ class Location extends @location {
7474
}
7575

7676
/** An empty location. */
77-
class EmptyLocation extends Location {
78-
EmptyLocation() { this.hasLocationInfo("", 0, 0, 0, 0) }
77+
class EmptyLocation extends Location, @location_default {
78+
EmptyLocation() { locations_default(this, _, -1, -1, -1, -1) }
79+
80+
override predicate hasLocationInfo(
81+
string filepath, int startline, int startcolumn, int endline, int endcolumn
82+
) {
83+
filepath = "" and
84+
startline = 0 and
85+
startcolumn = 0 and
86+
endline = 0 and
87+
endcolumn = 0
88+
}
89+
90+
override string toString() { result = "empty location" }
7991
}
8092

8193
/**
8294
* A location in source code, comprising of a source file and a segment of text
8395
* within the file.
8496
*/
8597
class SourceLocation extends Location, @location_default {
98+
SourceLocation() { not this instanceof EmptyLocation }
99+
86100
/** Gets the location that takes into account `#line` directives, if any. */
87101
SourceLocation getMappedLocation() {
88102
locations_mapped(this, result) and

0 commit comments

Comments
 (0)