Introduce benign errors.
Closes #25204 R=sigmund@google.com Review URL: https://codereview.chromium.org/1525593002.
This commit is contained in:
@@ -1250,6 +1250,32 @@ abstract class Compiler {
|
||||
_reporter.onCrashInUserCode(message, exception, stackTrace);
|
||||
}
|
||||
|
||||
/// Messages for which compile-time errors are reported but compilation
|
||||
/// continues regardless.
|
||||
static const List<MessageKind> BENIGN_ERRORS = const <MessageKind>[
|
||||
MessageKind.INVALID_METADATA,
|
||||
MessageKind.INVALID_METADATA_GENERIC,
|
||||
];
|
||||
|
||||
bool markCompilationAsFailed(DiagnosticMessage message, api.Diagnostic kind) {
|
||||
if (testMode) {
|
||||
// When in test mode, i.e. on the build-bot, we always stop compilation.
|
||||
return true;
|
||||
}
|
||||
if (reporter.options.fatalWarnings) {
|
||||
return true;
|
||||
}
|
||||
return !BENIGN_ERRORS.contains(message.message.kind);
|
||||
}
|
||||
|
||||
void fatalDiagnosticReported(DiagnosticMessage message,
|
||||
List<DiagnosticMessage> infos,
|
||||
api.Diagnostic kind) {
|
||||
if (markCompilationAsFailed(message, kind)) {
|
||||
compilationFailed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the [resolvedUri] into a readable URI.
|
||||
*
|
||||
@@ -1701,13 +1727,13 @@ class _CompilerDiagnosticReporter extends DiagnosticReporter {
|
||||
void reportDiagnostic(DiagnosticMessage message,
|
||||
List<DiagnosticMessage> infos,
|
||||
api.Diagnostic kind) {
|
||||
compiler.reportDiagnostic(message, infos, kind);
|
||||
if (kind == api.Diagnostic.ERROR ||
|
||||
kind == api.Diagnostic.CRASH ||
|
||||
(options.fatalWarnings &&
|
||||
kind == api.Diagnostic.WARNING)) {
|
||||
compiler.compilationFailed = true;
|
||||
compiler.fatalDiagnosticReported(message, infos, kind);
|
||||
}
|
||||
compiler.reportDiagnostic(message, infos, kind);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
// Test that benign error do not prevent compilation.
|
||||
|
||||
import 'memory_compiler.dart';
|
||||
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
import 'package:compiler/src/compiler.dart';
|
||||
import 'package:compiler/src/diagnostics/messages.dart';
|
||||
import 'package:compiler/src/js_backend/js_backend.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
main() {
|
||||
asyncTest(() async {
|
||||
for (MessageKind kind in Compiler.BENIGN_ERRORS) {
|
||||
await testExamples(kind);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
testExamples(MessageKind kind) async {
|
||||
MessageTemplate template = MessageTemplate.TEMPLATES[kind];
|
||||
for (var example in template.examples) {
|
||||
if (example is! Map) {
|
||||
example = {'main.dart': example};
|
||||
}
|
||||
DiagnosticCollector collector = new DiagnosticCollector();
|
||||
CompilationResult result = await runCompiler(
|
||||
memorySourceFiles: example,
|
||||
diagnosticHandler: collector);
|
||||
Expect.isTrue(result.isSuccess);
|
||||
Expect.isTrue(
|
||||
collector.errors.any((message) => message.messageKind == kind));
|
||||
Compiler compiler = result.compiler;
|
||||
JavaScriptBackend backend = compiler.backend;
|
||||
Expect.isNotNull(backend.generatedCode[compiler.mainFunction]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user