Skip to content

Commit 50c2683

Browse files
authored
Merge pull request github#11181 from github/alexdenisov/extractor-errors-suite
Swift: add an internal query-suite for listing all the compiler errors
2 parents c537c80 + dacbf4e commit 50c2683

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed
Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
private import codeql.swift.generated.Diagnostics
22

33
class Diagnostics extends Generated::Diagnostics {
4-
override string toString() { result = getText() }
4+
override string toString() { result = this.getSeverity() + ": " + this.getText() }
5+
6+
string getSeverity() {
7+
this.getKind() = 1 and result = "error"
8+
or
9+
this.getKind() = 2 and result = "warning"
10+
or
11+
this.getKind() = 3 and result = "note"
12+
or
13+
this.getKind() = 4 and result = "remark"
14+
}
15+
}
16+
17+
class CompilerError extends Diagnostics {
18+
CompilerError() { this.getSeverity() = "error" }
19+
}
20+
21+
class CompilerWarning extends Diagnostics {
22+
CompilerWarning() { this.getSeverity() = "warning" }
23+
}
24+
25+
class CompilerNote extends Diagnostics {
26+
CompilerNote() { this.getSeverity() = "note" }
27+
}
28+
29+
class CompilerRemark extends Diagnostics {
30+
CompilerRemark() { this.getSeverity() = "remark" }
531
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @name Compiler errors
3+
* @description List all compiler errors for files in the source code directory.
4+
* @kind diagnostic
5+
* @id swift/diagnostics/extraction-errors
6+
*/
7+
8+
import swift
9+
10+
from CompilerError error
11+
select error, "Compiler error in " + error.getFile() + " with error message " + error.getText()
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| diags.swift:1:10:1:10 | Hello, warning | getText: | Hello, warning | getKind: | 2 |
2-
| error.swift:2:14:2:14 | cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
3-
| import-error.swift:2:8:2:8 | no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |
1+
| diags.swift:1:10:1:10 | warning: Hello, warning | getText: | Hello, warning | getKind: | 2 |
2+
| error.swift:2:14:2:14 | error: cannot convert value of type 'String' to specified type 'Int' | getText: | cannot convert value of type 'String' to specified type 'Int' | getKind: | 1 |
3+
| import-error.swift:2:8:2:8 | error: no such module 'FooBar' | getText: | no such module 'FooBar' | getKind: | 1 |

0 commit comments

Comments
 (0)