mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[DiagnosticVerifier] don't repeat diagnostics in other files
`verifyUnknown()` and `verifyUnrelated()` would not remove the diagnostics after reporting their errors, leading to the same diagnostics then being emitted a second time. This removes them from the list after emitting them, just like `verifyFile()` does.
This commit is contained in:
@@ -386,19 +386,23 @@ static void autoApplyFixes(SourceManager &SM, unsigned BufferID,
|
||||
bool DiagnosticVerifier::verifyUnknown(
|
||||
std::vector<CapturedDiagnosticInfo> &CapturedDiagnostics) const {
|
||||
bool HadError = false;
|
||||
for (unsigned i = 0, e = CapturedDiagnostics.size(); i != e; ++i) {
|
||||
if (CapturedDiagnostics[i].Loc.isValid())
|
||||
auto CapturedDiagIter = CapturedDiagnostics.begin();
|
||||
while (CapturedDiagIter != CapturedDiagnostics.end()) {
|
||||
if (CapturedDiagIter->Loc.isValid()) {
|
||||
++CapturedDiagIter;
|
||||
continue;
|
||||
}
|
||||
|
||||
HadError = true;
|
||||
std::string Message =
|
||||
("unexpected " +
|
||||
getDiagKindString(CapturedDiagnostics[i].Classification) +
|
||||
" produced: " + CapturedDiagnostics[i].Message)
|
||||
getDiagKindString(CapturedDiagIter->Classification) +
|
||||
" produced: " + CapturedDiagIter->Message)
|
||||
.str();
|
||||
|
||||
auto diag = SM.GetMessage({}, llvm::SourceMgr::DK_Error, Message, {}, {});
|
||||
printDiagnostic(diag);
|
||||
CapturedDiagIter = CapturedDiagnostics.erase(CapturedDiagIter);
|
||||
}
|
||||
|
||||
if (HadError) {
|
||||
@@ -414,17 +418,20 @@ bool DiagnosticVerifier::verifyUnknown(
|
||||
bool DiagnosticVerifier::verifyUnrelated(
|
||||
std::vector<CapturedDiagnosticInfo> &CapturedDiagnostics) const {
|
||||
bool HadError = false;
|
||||
for (unsigned i = 0, e = CapturedDiagnostics.size(); i != e; ++i) {
|
||||
SourceLoc Loc = CapturedDiagnostics[i].Loc;
|
||||
if (!Loc.isValid())
|
||||
auto CapturedDiagIter = CapturedDiagnostics.begin();
|
||||
while (CapturedDiagIter != CapturedDiagnostics.end()) {
|
||||
SourceLoc Loc = CapturedDiagIter->Loc;
|
||||
if (!Loc.isValid()) {
|
||||
++CapturedDiagIter;
|
||||
// checked by verifyUnknown
|
||||
continue;
|
||||
}
|
||||
|
||||
HadError = true;
|
||||
std::string Message =
|
||||
("unexpected " +
|
||||
getDiagKindString(CapturedDiagnostics[i].Classification) +
|
||||
" produced: " + CapturedDiagnostics[i].Message)
|
||||
getDiagKindString(CapturedDiagIter->Classification) +
|
||||
" produced: " + CapturedDiagIter->Message)
|
||||
.str();
|
||||
|
||||
auto diag = SM.GetMessage(Loc, llvm::SourceMgr::DK_Error, Message, {}, {});
|
||||
@@ -450,6 +457,7 @@ bool DiagnosticVerifier::verifyUnrelated(
|
||||
"ignore diagnostics in this file"),
|
||||
{}, {});
|
||||
printDiagnostic(noteDiag);
|
||||
CapturedDiagIter = CapturedDiagnostics.erase(CapturedDiagIter);
|
||||
}
|
||||
|
||||
return HadError;
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
// RUN: not %target-typecheck-verify-swift -I %S/Inputs/broken-c-module 2>&1 | %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
|
||||
|
||||
// CHECK: <unknown>:0: error: fatal error encountered while in -verify mode
|
||||
// CHECK: [[@LINE+7]]:8: error: unexpected error produced: could not build
|
||||
// CHECK: [[@LINE+5]]:8: error: unexpected error produced: could not build
|
||||
// CHECK: error: unexpected note produced: in file included from <module-includes>:1:
|
||||
// CHECK: note: file '<module-includes>' is not parsed for 'expected' statements. Use '-verify-additional-file <module-includes>' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
|
||||
// CHECK: error: unexpected error produced: expected function body after function declarator
|
||||
// CHECK: note: file '{{.*}}broken_c.h' is not parsed for 'expected' statements. Use '-verify-additional-file {{.*}}broken_c.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
|
||||
// CHECK: note: diagnostic produced elsewhere: in file included from <module-includes>
|
||||
// CHECK: broken_c.h:2:11: error: diagnostic produced elsewhere: expected function body after function declarator
|
||||
import BrokenCModule
|
||||
|
||||
@@ -60,28 +60,3 @@ module TestClang {
|
||||
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
|
||||
// CHECK: TEST_H:1:6: note: in expansion from here
|
||||
// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
|
||||
|
||||
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop|
|
||||
// CHECK: TEST_H:1:25: note: in expansion from here
|
||||
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
|
||||
// CHECK: TEST_H:1:6: note: in expansion from here
|
||||
|
||||
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
|
||||
// CHECK: TEST_H:1:25: note: in expansion from here
|
||||
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
|
||||
// CHECK: TEST_H:1:6: note: in expansion from here
|
||||
|
||||
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!|
|
||||
// CHECK: TEST_H:1:25: note: in expansion from here
|
||||
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
|
||||
// CHECK: TEST_H:1:6: note: in expansion from here
|
||||
|
||||
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)|
|
||||
// CHECK: TEST_H:1:25: note: in expansion from here
|
||||
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
|
||||
// CHECK: TEST_H:1:6: note: in expansion from here
|
||||
|
||||
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}|
|
||||
// CHECK: TEST_H:1:25: note: in expansion from here
|
||||
// CHECK: <empty-filename>:1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
|
||||
// CHECK: TEST_H:1:6: note: in expansion from here
|
||||
|
||||
@@ -34,4 +34,3 @@ fn(()) // expected-error {{argument passed to call that takes no arguments}}
|
||||
let x: Array<Int, Int>
|
||||
// CHECK: error: unexpected note produced: generic struct 'Array' declared here
|
||||
// CHECK: note: file 'Swift.Array' is not parsed for 'expected' statements. Use '-verify-additional-file Swift.Array' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
|
||||
// CHECK: note: diagnostic produced elsewhere: generic struct 'Array' declared here
|
||||
|
||||
@@ -44,7 +44,6 @@ extension Crap {} // expected-error {{non-nominal type 'Crap' (aka '() -> ()') c
|
||||
|
||||
// CHECK: error: unexpected note produced: 'Bool' declared here
|
||||
// CHECK: note: file 'Swift.Bool' is not parsed for 'expected' statements. Use '-verify-additional-file Swift.Bool' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
|
||||
// CHECK: note: diagnostic produced elsewhere: 'Bool' declared here
|
||||
|
||||
// Verify the serialized diags have the right magic at the top.
|
||||
// CHECK-SERIALIZED: DIA
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
|
||||
|
||||
// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -verify-ignore-unknown -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
|
||||
// README: If you just added support for protocol composition to the
|
||||
// ClangTypeConverter, please update this test to use a different type that we
|
||||
// don't support so the error messages here are still tested.
|
||||
|
||||
Reference in New Issue
Block a user