mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 08:44:27 +00:00
Check for missing required libraries dart:core and dart:async.
R=brianwilkerson@google.com Bug: https://github.com/dart-lang/sdk/issues/32686 Change-Id: I337cb61911061f25b501a5615fe40c02b9749b19 Reviewed-on: https://dart-review.googlesource.com/48703 Commit-Queue: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
d53291d156
commit
f201ace7f3
5 changed files with 61 additions and 1 deletions
|
@ -168,6 +168,7 @@ const List<ErrorCode> errorCodeValues = const [
|
|||
CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME,
|
||||
CompileTimeErrorCode.MISSING_CONST_IN_LIST_LITERAL,
|
||||
CompileTimeErrorCode.MISSING_CONST_IN_MAP_LITERAL,
|
||||
CompileTimeErrorCode.MISSING_DART_LIBRARY,
|
||||
CompileTimeErrorCode.MIXIN_DECLARES_CONSTRUCTOR,
|
||||
CompileTimeErrorCode.MIXIN_DEFERRED_CLASS,
|
||||
CompileTimeErrorCode.MIXIN_HAS_NO_CONSTRUCTORS,
|
||||
|
|
|
@ -28,6 +28,7 @@ import 'package:analyzer/src/dart/analysis/search.dart';
|
|||
import 'package:analyzer/src/dart/analysis/session.dart';
|
||||
import 'package:analyzer/src/dart/analysis/status.dart';
|
||||
import 'package:analyzer/src/dart/analysis/top_level_declaration.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart'
|
||||
show
|
||||
AnalysisContext,
|
||||
|
@ -1201,6 +1202,12 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
useCFE: _analysisOptions.useFastaParser,
|
||||
frontEndCompiler: _frontEndCompiler);
|
||||
} else {
|
||||
if (!_fsState.getFileForUri(Uri.parse('dart:core')).exists) {
|
||||
return _newMissingDartLibraryResult(file, 'dart:core');
|
||||
}
|
||||
if (!_fsState.getFileForUri(Uri.parse('dart:async')).exists) {
|
||||
return _newMissingDartLibraryResult(file, 'dart:async');
|
||||
}
|
||||
libraryContext = await _createLibraryContext(library);
|
||||
analyzer = new LibraryAnalyzer(
|
||||
_logger,
|
||||
|
@ -1505,6 +1512,30 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* We detected that one of the required `dart` libraries is missing.
|
||||
* Return the empty analysis result with the error.
|
||||
*/
|
||||
AnalysisResult _newMissingDartLibraryResult(
|
||||
FileState file, String missingUri) {
|
||||
// TODO(scheglov) Find a better way to report this.
|
||||
return new AnalysisResult(
|
||||
this,
|
||||
_sourceFactory,
|
||||
file.path,
|
||||
file.uri,
|
||||
file.exists,
|
||||
null,
|
||||
file.lineInfo,
|
||||
null,
|
||||
null,
|
||||
[
|
||||
new AnalysisError(file.source, 0, 0,
|
||||
CompileTimeErrorCode.MISSING_DART_LIBRARY, [missingUri])
|
||||
],
|
||||
null);
|
||||
}
|
||||
|
||||
void _reportException(String path, exception, StackTrace stackTrace) {
|
||||
String contextKey = null;
|
||||
if (exception is _ExceptionState) {
|
||||
|
|
|
@ -149,7 +149,8 @@ class FileState {
|
|||
: isInExternalSummaries = true,
|
||||
path = null,
|
||||
fileUri = null,
|
||||
source = null {
|
||||
source = null,
|
||||
_exists = true {
|
||||
_apiSignature = new Uint8List(16);
|
||||
}
|
||||
|
||||
|
|
|
@ -1609,6 +1609,11 @@ class CompileTimeErrorCode extends ErrorCode {
|
|||
"expression.",
|
||||
correction: "Try adding the keyword 'const' before the literal.");
|
||||
|
||||
static const CompileTimeErrorCode MISSING_DART_LIBRARY =
|
||||
const CompileTimeErrorCode(
|
||||
'MISSING_DART_LIBRARY', "Required library '{0}' is missing.",
|
||||
correction: "Check your Dart SDK installation for completeness.");
|
||||
|
||||
/**
|
||||
* 9 Mixins: It is a compile-time error if a declared or derived mixin
|
||||
* explicitly declares a constructor.
|
||||
|
|
|
@ -7844,6 +7844,28 @@ import 'b.dart';
|
|||
expect(driver.knownFiles, isNot(contains(b)));
|
||||
}
|
||||
|
||||
test_missingDartLibrary_async() async {
|
||||
provider.getFile(MockSdk.FULL_URI_MAP['dart:async']).delete();
|
||||
addTestFile('class C {}');
|
||||
|
||||
ErrorsResult result = await driver.getErrors(testFile);
|
||||
expect(result.errors, hasLength(1));
|
||||
|
||||
AnalysisError error = result.errors[0];
|
||||
expect(error.errorCode, CompileTimeErrorCode.MISSING_DART_LIBRARY);
|
||||
}
|
||||
|
||||
test_missingDartLibrary_core() async {
|
||||
provider.getFile(MockSdk.FULL_URI_MAP['dart:core']).delete();
|
||||
addTestFile('class C {}');
|
||||
|
||||
ErrorsResult result = await driver.getErrors(testFile);
|
||||
expect(result.errors, hasLength(1));
|
||||
|
||||
AnalysisError error = result.errors[0];
|
||||
expect(error.errorCode, CompileTimeErrorCode.MISSING_DART_LIBRARY);
|
||||
}
|
||||
|
||||
test_parseFile_notAbsolutePath() async {
|
||||
try {
|
||||
await driver.parseFile('not_absolute.dart');
|
||||
|
|
Loading…
Reference in a new issue