Skip to content

Commit 1a708af

Browse files
committed
Include compilation errors in diagnostic check
1 parent 64354bb commit 1a708af

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed
Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,55 @@
11
/**
22
* @name Extraction errors
3-
* @description List all errors reported by the extractor. The returned issues are
4-
* limited to those files where there are no compilation errors. This
5-
* indicates a bug or limitation in the extractor, and could lead to
6-
* inaccurate results.
3+
* @description List all errors reported by the extractor or the compiler. Extractor errors are
4+
* limited to those files where there are no compilation errors.
75
* @kind diagnostic
86
* @id cs/diagnostics/extraction-errors
97
*/
108

119
import csharp
1210
import semmle.code.csharp.commons.Diagnostics
1311

14-
private string getLocation(ExtractorError error) {
15-
if error.getLocation().getFile().fromSource()
16-
then result = " in " + error.getLocation().getFile()
17-
else result = ""
12+
private newtype TDiagnosticError =
13+
TCompilerError(CompilerError c) or
14+
TExtractorError(ExtractorError e)
15+
16+
abstract private class DiagnosticError extends TDiagnosticError {
17+
string getMessage() { none() }
18+
19+
string toString() { none() }
20+
21+
string getLocation(Location l) {
22+
if l.getFile().fromSource() then result = " in " + l.getFile() else result = ""
23+
}
24+
}
25+
26+
private class DiagnosticCompilerError extends DiagnosticError {
27+
CompilerError c;
28+
29+
DiagnosticCompilerError() { this = TCompilerError(c) }
30+
31+
override string getMessage() {
32+
result = "Compiler error" + getLocation(c.getLocation()) + ": " + c.getMessage()
33+
}
34+
35+
override string toString() { result = c.toString() }
36+
}
37+
38+
private class DiagnosticExtractorError extends DiagnosticError {
39+
ExtractorError e;
40+
41+
DiagnosticExtractorError() {
42+
this = TExtractorError(e) and
43+
not exists(CompilerError ce | ce.getLocation().getFile() = e.getLocation().getFile())
44+
}
45+
46+
override string getMessage() {
47+
result =
48+
"Unexpected " + e.getOrigin() + " error" + getLocation(e.getLocation()) + ": " + e.getText()
49+
}
50+
51+
override string toString() { result = e.toString() }
1852
}
1953

20-
from ExtractorError error
21-
where not exists(CompilerError ce | ce.getLocation().getFile() = error.getLocation().getFile())
22-
select error,
23-
"Unexpected " + error.getOrigin() + " error" + getLocation(error) + ": " + error.getText(), 3
54+
from DiagnosticError error
55+
select error.getMessage(), 3
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @name Successfully extracted files
33
* @description A list of all files in the source code directory that were extracted
4-
* without encountering an extraction error in the file.
4+
* without encountering an extraction or compiler error in the file.
55
* @kind diagnostic
66
* @id cs/diagnostics/successfully-extracted-files
77
*/
@@ -10,5 +10,8 @@ import csharp
1010
import semmle.code.csharp.commons.Diagnostics
1111

1212
from File file
13-
where file.fromSource() and not exists(ExtractorError e | e.getLocation().getFile() = file)
13+
where
14+
file.fromSource() and
15+
not exists(ExtractorError e | e.getLocation().getFile() = file) and
16+
not exists(CompilerError e | e.getLocation().getFile() = file)
1417
select file, ""
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| Program.cs:9:32:9:46 | Unable to resolve target for call. (Compilation error?) | Unexpected C# extractor error in Program.cs: Unable to resolve target for call. (Compilation error?) | 3 |
1+
| Unexpected C# extractor error in Program.cs: Unable to resolve target for call. (Compilation error?) | 3 |

0 commit comments

Comments
 (0)