Skip to content

Commit db44bf7

Browse files
committed
Add support in the diagnostic verifier for verifying no fix-its
Checked what it would look like to verify fix-its in every case, and currently the tests are missing expected fix-its in 435 diagnoses in 60 test files. So as an alternative, added support for a no fix-its marker “{{none}}”, and added that marker to the c-style for deprecation tests where it applies.
1 parent 0c0a0fa commit db44bf7

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ namespace {
3939
// This is true if a '*' constraint is present to say that the diagnostic
4040
// may appear (or not) an uncounted number of times.
4141
bool mayAppear = false;
42+
43+
// This is true if a '{{none}}' is present to mark that there should be no
44+
// fixits at all.
45+
bool noFixitsMayAppear = false;
4246

4347
// This is the raw input buffer for the message text, the part in the
4448
// {{...}}
@@ -358,6 +362,12 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
358362
// Prepare for the next round of checks.
359363
ExtraChecks = ExtraChecks.substr(EndLoc+2).ltrim();
360364

365+
// Special case for specifying no fixits should appear.
366+
if (FixItStr == "none") {
367+
Expected.noFixitsMayAppear = true;
368+
continue;
369+
}
370+
361371
// Parse the pieces of the fix-it.
362372
size_t MinusLoc = FixItStr.find('-');
363373
if (MinusLoc == StringRef::npos) {
@@ -467,20 +477,17 @@ bool DiagnosticVerifier::verifyFile(unsigned BufferID,
467477
llvm::SMFixIt fix(llvm::SMRange(replStartLoc, replEndLoc), actual);
468478
addError(IncorrectFixit,
469479
"expected fix-it not seen; actual fix-its: " + actual, fix);
470-
#if 0 // TODO: There are still some bugs with this, and we don't have a
471-
// policy of requiring a fixit specification on tests.
472-
} else if (expected.Fixits.empty() &&
480+
} else if (expected.noFixitsMayAppear &&
473481
!FoundDiagnostic.getFixIts().empty() &&
474-
!expected.mayAppear &&
475-
false) {
482+
!expected.mayAppear) {
476483
// If there was no fixit specification, but some were produced, add a
477484
// fixit to add them in.
478485
auto actual = renderFixits(FoundDiagnostic.getFixIts(), InputFile);
479-
480-
llvm::SMFixIt fix(SMLoc::getFromPointer(expected.ExpectedEnd),
481-
" " + actual);
482-
addError(expected.ExpectedEnd, "expected fix-it not specified", fix);
483-
#endif
486+
auto replStartLoc = SMLoc::getFromPointer(expected.ExpectedEnd - 8); // {{none}} length
487+
auto replEndLoc = SMLoc::getFromPointer(expected.ExpectedEnd - 1);
488+
489+
llvm::SMFixIt fix(llvm::SMRange(replStartLoc, replEndLoc), actual);
490+
addError(replStartLoc.getPointer(), "expected no fix-its; actual fix-it seen: " + actual, fix);
484491
}
485492

486493
// Actually remove the diagnostic from the list, so we don't match it

test/Sema/diag_c_style_for.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ for var d=100;d<5;d++ { // expected-warning {{C-style for statement is deprecate
1818

1919
// next three aren't auto-fixable
2020
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
21-
for var e = 3; e > 4; e++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
21+
for var e = 3; e > 4; e++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
2222
}
2323

2424
// expected-warning @+1 {{'--' is deprecated: it will be removed in Swift 3}}
25-
for var f = 3; f < 4; f-- { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
25+
for var f = 3; f < 4; f-- { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
2626
}
2727

2828
let start = Int8(4)
2929
let count = Int8(10)
3030
var other = Int8(2)
3131

3232
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
33-
for ; other<count; other++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
33+
for ; other<count; other++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
3434
}
3535

3636
// this should be fixable, and keep the type
@@ -41,15 +41,15 @@ for (var number : Int8 = start; number < count; number++) { // expected-warning
4141

4242
// should produce extra note
4343
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
44-
for (var m : Int8 = start; m < count; ++m) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} expected-note {{C-style for statement can't be automatically fixed to for-in, because the loop variable is modified inside the loop}}
44+
for (var m : Int8 = start; m < count; ++m) { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}} expected-note {{C-style for statement can't be automatically fixed to for-in, because the loop variable is modified inside the loop}}
4545
m += 3
4646
}
4747

4848
// could theoretically fix this (and more like it if we auto-suggested "stride:")
49-
for var o = 2; o < 888; o += 1 { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
49+
for var o = 2; o < 888; o += 1 { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
5050
}
5151

5252
// could theoretically fix this with "..."
5353
// expected-warning @+1 {{'++' is deprecated: it will be removed in Swift 3}}
54-
for var p = 2; p <= 8; p++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}}
55-
}
54+
for var p = 2; p <= 8; p++ { // expected-warning {{C-style for statement is deprecated and will be removed in a future version of Swift}} {{none}}
55+
}

0 commit comments

Comments
 (0)