[cfe] Assert verification errors
This adds assertions that no verification errors are found.
This enables the distinction between compile-time errors and
verification during trybot testing, leaving the latter as crashes
rather than (unexpected) compile-time errors, while retaining the
good diagnostics.
Change-Id: I097d875a75e8343c67cb96190b53320d4799663c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309662
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
diff --git a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
index 1a53c51..f5812d0 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
@@ -580,7 +580,8 @@
/// component.
Future<BuildResult> buildComponent(
{required MacroApplications? macroApplications,
- bool verify = false}) async {
+ bool verify = false,
+ bool allowVerificationErrorForTesting = false}) async {
if (loader.roots.isEmpty) {
return new BuildResult(macroApplications: macroApplications);
}
@@ -637,7 +638,8 @@
if (verify) {
benchmarker?.enterPhase(BenchmarkPhases.body_verify);
- this.verify();
+ _verify(
+ allowVerificationErrorForTesting: allowVerificationErrorForTesting);
}
benchmarker?.enterPhase(BenchmarkPhases.body_installAllComponentProblems);
@@ -1616,11 +1618,13 @@
return constants.EvaluationMode.fromNnbdMode(loader.nnbdMode);
}
- void verify() {
+ void _verify({required bool allowVerificationErrorForTesting}) {
// TODO(ahe): How to handle errors.
- verifyComponent(context.options.target,
+ List<LocatedMessage> errors = verifyComponent(context.options.target,
VerificationStage.afterModularTransformations, component!,
skipPlatform: context.options.skipPlatformVerification);
+ assert(allowVerificationErrorForTesting || errors.isEmpty,
+ "Verification errors found.");
ClassHierarchy hierarchy =
new ClassHierarchy(component!, new CoreTypes(component!),
onAmbiguousSupertypes: (Class cls, Supertype a, Supertype b) {
diff --git a/pkg/front_end/lib/src/kernel_generator_impl.dart b/pkg/front_end/lib/src/kernel_generator_impl.dart
index 5a64788..cf6daf5 100644
--- a/pkg/front_end/lib/src/kernel_generator_impl.dart
+++ b/pkg/front_end/lib/src/kernel_generator_impl.dart
@@ -146,10 +146,12 @@
List<int>? summary = null;
if (buildSummary) {
if (options.verify) {
- for (LocatedMessage error in verifyComponent(
- options.target, VerificationStage.outline, summaryComponent)) {
+ List<LocatedMessage> errors = verifyComponent(
+ options.target, VerificationStage.outline, summaryComponent);
+ for (LocatedMessage error in errors) {
options.report(error, Severity.error);
}
+ assert(errors.isEmpty, "Verification errors found.");
}
if (options.debugDump) {
printComponentText(summaryComponent,
diff --git a/pkg/front_end/test/fasta/testing/suite.dart b/pkg/front_end/test/fasta/testing/suite.dart
index a00c492..ebe4d84 100644
--- a/pkg/front_end/test/fasta/testing/suite.dart
+++ b/pkg/front_end/test/fasta/testing/suite.dart
@@ -2380,7 +2380,8 @@
macroApplications: buildResult.macroApplications,
verify: compilationSetup.folderOptions.noVerify
? false
- : context.verify);
+ : context.verify,
+ allowVerificationErrorForTesting: true);
p = buildResult.component!;
instrumentation.finish();
if (instrumentation.hasProblems) {