Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1011)

Unified Diff: pkg/front_end/lib/src/fasta/kernel/kernel_target.dart

Issue 2938573002: Improve recovery from compile-time errors. (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/lib/src/fasta/loader.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
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 1b439b29346950495eb61bc4a0e1dd3413bf7218..f749d5c902ba3f0fbfd16f04327a5a6a323bc0ae 100644
--- a/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
+++ b/pkg/front_end/lib/src/fasta/kernel/kernel_target.dart
@@ -9,6 +9,7 @@ import 'dart:async' show Future;
import 'dart:io' show File;
import 'package:front_end/file_system.dart';
+
import 'package:kernel/ast.dart'
show
Arguments,
@@ -26,6 +27,7 @@ import 'package:kernel/ast.dart'
Initializer,
InvalidInitializer,
Library,
+ ListLiteral,
Name,
NamedExpression,
NullLiteral,
@@ -109,10 +111,6 @@ class KernelTarget extends TargetImplementation {
loader = createLoader();
}
- bool get hasErrors {
- return errors.isNotEmpty || loader.collectCompileTimeErrors().isNotEmpty;
- }
-
void addError(file, int charOffset, String message) {
Uri uri = file is String ? Uri.parse(file) : file;
InputError error = new InputError(uri, charOffset, message);
@@ -285,16 +283,14 @@ class KernelTarget extends TargetImplementation {
loader.finishStaticInvocations();
finishAllConstructors();
loader.finishNativeMethods();
- if (!hasErrors) {
- runBuildTransformations();
- }
+ runBuildTransformations();
if (verify) this.verify();
- errors.addAll(loader.collectCompileTimeErrors().map((e) => e.format()));
if (errors.isNotEmpty) {
handleInputError(null,
isFullProgram: true, trimDependencies: trimDependencies);
}
+ handleRecoverableErrors(loader.unhandledErrors);
} on InputError catch (e) {
handleInputError(e,
isFullProgram: true, trimDependencies: trimDependencies);
@@ -349,6 +345,31 @@ class KernelTarget extends TargetImplementation {
ticker.logMs("Wrote deps file");
}
+ /// Adds a synthetic field named `#errors` to the main library that contains
+ /// [recoverableErrors] formatted.
+ ///
+ /// If [recoverableErrors] is empty, this method does nothing.
+ ///
+ /// If there's no main library, this method uses [erroneousProgram] to
+ /// replace [program].
+ void handleRecoverableErrors(List<InputError> recoverableErrors) {
+ if (recoverableErrors.isEmpty) return;
+ KernelLibraryBuilder mainLibrary = loader.first;
+ if (mainLibrary == null) {
+ program = erroneousProgram(true);
+ return;
+ }
+ List<Expression> expressions = <Expression>[];
+ for (InputError error in recoverableErrors) {
+ String message = error.format();
+ errors.add(message);
+ expressions.add(new StringLiteral(message));
+ }
+ mainLibrary.library.addMember(new Field(new Name("#errors"),
+ initializer: new ListLiteral(expressions, isConst: true),
+ isConst: true));
+ }
+
Program erroneousProgram(bool isFullProgram) {
Uri uri = loader.first?.uri ?? Uri.parse("error:error");
Uri fileUri = loader.first?.fileUri ?? uri;
« no previous file with comments | « pkg/front_end/lib/src/fasta/kernel/body_builder.dart ('k') | pkg/front_end/lib/src/fasta/loader.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698