Skip to content

Commit 3afbe31

Browse files
authored
Merge pull request #27448 from owenv/verifier_docs
[Docs] Add a section to Diagnostics.md on -verify mode
2 parents 829df91 + f749e85 commit 3afbe31

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

docs/Diagnostics.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,19 @@ Most diagnostics have no reason to change behavior under editor mode. An example
104104
- `%error` - Represents a branch in a `%select` that should never be taken. In debug builds of the compiler this produces an assertion failure.
105105

106106
- `%%` - Emits a literal percent sign.
107+
108+
### Diagnostic Verifier ###
109+
110+
(This section is specific to the Swift compiler's diagnostic engine.)
111+
112+
If the `-verify` frontend flag is used, the Swift compiler will check emitted diagnostics against specially formatted comments in the source. This feature is used extensively throughout the test suite to ensure diagnostics are emitted with the correct message and source location.
113+
114+
An expected diagnostic is denoted by a comment which begins with `expected-error`, `expected-warning`, `expected-note`, or `expected-remark`. It is followed by:
115+
116+
- (Optional) Location information. By default, the comment will match any diagnostic emitted on the same line. However, it's possible to override this behavior and/or specify column information as well. `// expected-error@-1 ...` looks for an error on the previous line, `// expected-warning@+1:3 ...` looks for a warning on the next line at the third column, and `// expected-note@:7 ...` looks for a note on the same line at the seventh column.
117+
118+
- (Optional) A match count which specifies how many times the diagnostic is expected to appear. This may be a positive integer or `*`, which allows for zero or more matches. The match count must be surrounded by whitespace if present. For example, `// expected-error 2 ...` looks for two matching errors, and `// expected-warning * ...` looks for any number of matching warnings.
119+
120+
- (Required) The expected error message. The message should be enclosed in double curly braces and should not include the `error:`/`warning:`/`note:`/`remark:` prefix. For example, `// expected-error {{invalid redeclaration of 'y'}}` would match an error with that message on the same line. The expected message does not need to match the emitted message verbatim. As long as the expected message is a substring of the original message, they will match.
121+
122+
- (Optional) Expected fix-its. These are each enclosed in double curly braces and appear after the expected message. An expected fix-it consists of a column range followed by the text it's expected to be replaced with. For example, `let r : Int i = j // expected-error{{consecutive statements}} {{12-12=;}}` will match a fix-it attached to the consecutive statements error which inserts a semicolon at column 12, just after the 't' in 'Int'. The special {{none}} specifier is also supported, which will cause the diagnostic match to fail if unexpected fix-its are produced.

docs/Testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ code for the target that is not the build machine:
232232

233233
* ``%target-typecheck-verify-swift``: parse and type check the current Swift file
234234
for the target platform and verify diagnostics, like ``swift -frontend -typecheck -verify
235-
%s``.
235+
%s``. For further explanation of `-verify` mode, see [Diagnostics.md](Diagnostics.md).
236236

237237
Use this substitution for testing semantic analysis in the compiler.
238238

0 commit comments

Comments
 (0)