-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C#: Add extraction error diagnostic query #5740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5149ffd
C#: Add extraction error diagnostic query
tamasvajk 353d43a
Log model errors even in standalone extraction
tamasvajk b05e211
Fix failing test
tamasvajk ff9327a
Add diagnostic query to get correctly extracted files
tamasvajk 64354bb
Fix test results after rebase
tamasvajk 1a708af
Include compilation errors in diagnostic check
tamasvajk e3f10c0
Cleanup DiagnosticError classes
tamasvajk b4bd7af
Add change note
tamasvajk 51e08d4
Fix error severity
tamasvajk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| lgtm,codescanning | ||
| * Program model errors are now extracted in standalone extraction. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * @name Extraction errors | ||
| * @description List all errors reported by the extractor or the compiler. Extractor errors are | ||
| * limited to those files where there are no compilation errors. | ||
| * @kind diagnostic | ||
| * @id cs/diagnostics/extraction-errors | ||
| */ | ||
|
|
||
| import csharp | ||
| import semmle.code.csharp.commons.Diagnostics | ||
|
|
||
| private newtype TDiagnosticError = | ||
| TCompilerError(CompilerError c) or | ||
| TExtractorError(ExtractorError e) | ||
|
|
||
| abstract private class DiagnosticError extends TDiagnosticError { | ||
| abstract string getMessage(); | ||
|
|
||
| abstract string toString(); | ||
|
|
||
| abstract Location getLocation(); | ||
|
|
||
| string getLocationMessage() { | ||
| if getLocation().getFile().fromSource() | ||
| then result = " in " + getLocation().getFile() | ||
| else result = "" | ||
| } | ||
| } | ||
|
|
||
| private class DiagnosticCompilerError extends DiagnosticError { | ||
| CompilerError c; | ||
|
|
||
| DiagnosticCompilerError() { this = TCompilerError(c) } | ||
|
|
||
| override string getMessage() { | ||
| result = "Compiler error" + this.getLocationMessage() + ": " + c.getMessage() | ||
| } | ||
|
|
||
| override string toString() { result = c.toString() } | ||
|
|
||
| override Location getLocation() { result = c.getLocation() } | ||
| } | ||
|
|
||
| private class DiagnosticExtractorError extends DiagnosticError { | ||
| ExtractorError e; | ||
|
|
||
| DiagnosticExtractorError() { | ||
| this = TExtractorError(e) and | ||
| not exists(CompilerError ce | ce.getLocation().getFile() = e.getLocation().getFile()) | ||
| } | ||
|
|
||
| override string getMessage() { | ||
| result = | ||
| "Unexpected " + e.getOrigin() + " error" + this.getLocationMessage() + ": " + e.getText() | ||
| } | ||
|
|
||
| override string toString() { result = e.toString() } | ||
|
|
||
| override Location getLocation() { result = e.getLocation() } | ||
| } | ||
|
|
||
| from DiagnosticError error | ||
| select error.getMessage(), 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * @name Successfully extracted files | ||
| * @description A list of all files in the source code directory that were extracted | ||
| * without encountering an extraction or compiler error in the file. | ||
| * @kind diagnostic | ||
| * @id cs/diagnostics/successfully-extracted-files | ||
| */ | ||
|
|
||
| import csharp | ||
| import semmle.code.csharp.commons.Diagnostics | ||
|
|
||
| from File file | ||
| where | ||
| file.fromSource() and | ||
| not exists(ExtractorError e | e.getLocation().getFile() = file) and | ||
| not exists(CompilerError e | e.getLocation().getFile() = file) | ||
| select file, "" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| public class A | ||
| { | ||
| public void M() { } | ||
| } |
1 change: 1 addition & 0 deletions
1
csharp/ql/test/library-tests/diagnostics/DiagnosticExtractorErrors.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | Unexpected C# extractor error in Program.cs: Unable to resolve target for call. (Compilation error?) | 2 | |
1 change: 1 addition & 0 deletions
1
csharp/ql/test/library-tests/diagnostics/DiagnosticExtractorErrors.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Diagnostics/DiagnosticExtractionErrors.ql |
1 change: 1 addition & 0 deletions
1
csharp/ql/test/library-tests/diagnostics/DiagnosticNoExtractorErrors.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| | A.cs:0:0:0:0 | A.cs | | |
1 change: 1 addition & 0 deletions
1
csharp/ql/test/library-tests/diagnostics/DiagnosticNoExtractorErrors.qlref
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Diagnostics/DiagnosticNoExtractionErrors.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // semmle-extractor-options: --standalone | ||
|
|
||
| using System; | ||
|
|
||
| class Class | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| int z = GetParamLength(__arglist(1, 2)); | ||
| } | ||
|
|
||
| public static int GetParamLength(__arglist) | ||
| { | ||
| ArgIterator iterator = new ArgIterator(__arglist); | ||
| return iterator.GetRemainingCount(); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
csharp/ql/test/library-tests/standalone/errorrecovery/DiagnosticsAndErrors.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,13 @@ | ||
| compilationMessages | ||
| extractorMessages | ||
| | errors.cs:8:1:8:22 | Namespace not found | | ||
| | errors.cs:24:31:24:32 | Failed to determine type | | ||
| | errors.cs:24:31:24:40 | Failed to determine type | | ||
| | errors.cs:24:31:24:40 | Unable to resolve target for call. (Compilation error?) | | ||
| | errors.cs:24:38:24:39 | Failed to determine type | | ||
| | errors.cs:57:20:57:20 | Failed to determine type | | ||
| | errors.cs:93:45:93:45 | Failed to determine type | | ||
| | errors.cs:93:45:93:45 | Failed to resolve name | | ||
| | errors.cs:94:45:94:45 | Failed to determine type | | ||
| | errors.cs:94:45:94:45 | Failed to resolve name | | ||
| | file://:0:0:0:0 | Extracting default argument value 'object RecordNumber = default' instead of 'object RecordNumber = -1'. The latter is not supported in C#. | |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the
""needed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is needed. This is probably how we indicate that these results are success ones. See also here.