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; |