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

Unified Diff: pkg/compiler/lib/src/source_file_provider.dart

Issue 2951723002: Add closure_test for kernel based members (Closed)
Patch Set: Cleanup 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
Index: pkg/compiler/lib/src/source_file_provider.dart
diff --git a/pkg/compiler/lib/src/source_file_provider.dart b/pkg/compiler/lib/src/source_file_provider.dart
index 4a072bdaeea07b328003815b4d6573b15ca825c3..6e789816dc05e1ba6a8b2b39e9a58f1ccc7074d0 100644
--- a/pkg/compiler/lib/src/source_file_provider.dart
+++ b/pkg/compiler/lib/src/source_file_provider.dart
@@ -34,7 +34,7 @@ abstract class SourceFileProvider implements CompilerInput {
}
}
- Future<api.Input> _readFromFile(Uri resourceUri, api.InputKind inputKind) {
+ api.Input _readFromFileSync(Uri resourceUri, api.InputKind inputKind) {
assert(resourceUri.scheme == 'file');
List<int> source;
try {
@@ -43,8 +43,7 @@ abstract class SourceFileProvider implements CompilerInput {
} on FileSystemException catch (ex) {
String message = ex.osError?.message;
String detail = message != null ? ' ($message)' : '';
- return new Future.error(
- "Error reading '${relativizeUri(resourceUri)}' $detail");
+ throw "Error reading '${relativizeUri(resourceUri)}' $detail";
}
dartCharactersRead += source.length;
api.Input input;
@@ -58,6 +57,28 @@ abstract class SourceFileProvider implements CompilerInput {
break;
}
sourceFiles[resourceUri] = input;
+ return input;
+ }
+
+ /// Read [resourceUri] directly as a UTF-8 file. If reading fails, `null` is
+ /// returned.
+ api.Input autoReadFromFile(Uri resourceUri) {
+ try {
+ return _readFromFileSync(resourceUri, InputKind.utf8);
+ } catch (e) {
+ // Silence the error. The [resourceUri] was not requested by the user and
+ // was only needed to give better error messages.
+ }
+ return null;
+ }
+
+ Future<api.Input> _readFromFile(Uri resourceUri, api.InputKind inputKind) {
+ api.Input input;
+ try {
+ input = _readFromFileSync(resourceUri, inputKind);
+ } catch (e) {
+ return new Future.error(e);
+ }
return new Future.value(input);
}
@@ -147,6 +168,7 @@ class FormattingDiagnosticHandler implements CompilerDiagnostics {
bool isAborting = false;
bool enableColors = false;
bool throwOnError = false;
+ bool autoReadFileUri = false;
int throwOnErrorCount = 0;
api.Diagnostic lastKind = null;
int fatalCount = 0;
@@ -232,6 +254,14 @@ class FormattingDiagnosticHandler implements CompilerDiagnostics {
print('${color(message)}');
} else {
api.Input file = provider.sourceFiles[uri];
+ if (file == null &&
+ autoReadFileUri &&
+ uri.scheme == 'file' &&
+ uri.path.endsWith('.dart')) {
+ // When reading from .dill files, the original source files haven't been
+ // loaded. Load the file if possible to provide a better error message.
+ file = provider.autoReadFromFile(uri);
+ }
if (file is SourceFile) {
print(file.getLocationMessage(color(message), begin, end,
colorize: color));
« no previous file with comments | « pkg/compiler/lib/src/kernel/kernel_backend_strategy.dart ('k') | tests/compiler/dart2js/bad_output_io_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698