Report errors like IMPORT_OF_NON_LIBRARY with the new analysis driver.
R=brianwilkerson@google.com BUG= Review-Url: https://codereview.chromium.org/2627093010 .
This commit is contained in:
@@ -552,6 +552,7 @@ class GetHandler implements AbstractGetHandler {
|
||||
results.add(LINTS);
|
||||
results.add(INFERABLE_STATIC_VARIABLES_IN_UNIT);
|
||||
results.add(LIBRARY_UNIT_ERRORS);
|
||||
results.add(RESOLVE_DIRECTIVES_ERRORS);
|
||||
results.add(RESOLVE_TYPE_NAMES_ERRORS);
|
||||
results.add(RESOLVE_TYPE_BOUNDS_ERRORS);
|
||||
results.add(RESOLVE_UNIT_ERRORS);
|
||||
|
||||
@@ -1247,6 +1247,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
|
||||
setValue(HINTS, AnalysisError.NO_ERRORS);
|
||||
setValue(LINTS, AnalysisError.NO_ERRORS);
|
||||
setValue(LIBRARY_UNIT_ERRORS, AnalysisError.NO_ERRORS);
|
||||
setValue(RESOLVE_DIRECTIVES_ERRORS, AnalysisError.NO_ERRORS);
|
||||
setValue(RESOLVE_TYPE_NAMES_ERRORS, AnalysisError.NO_ERRORS);
|
||||
setValue(RESOLVE_UNIT_ERRORS, AnalysisError.NO_ERRORS);
|
||||
entry.setState(RESOLVED_UNIT, CacheState.FLUSHED);
|
||||
|
||||
@@ -2283,8 +2283,16 @@ class DeadCodeVerifier extends RecursiveAstVisitor<Object> {
|
||||
* by a [DirectiveElementBuilder].
|
||||
*/
|
||||
class DirectiveResolver extends SimpleAstVisitor {
|
||||
final Map<Source, int> sourceModificationTimeMap;
|
||||
final Map<Source, SourceKind> importSourceKindMap;
|
||||
final Map<Source, SourceKind> exportSourceKindMap;
|
||||
final List<AnalysisError> errors = <AnalysisError>[];
|
||||
|
||||
LibraryElement _enclosingLibrary;
|
||||
|
||||
DirectiveResolver(this.sourceModificationTimeMap, this.importSourceKindMap,
|
||||
this.exportSourceKindMap);
|
||||
|
||||
@override
|
||||
void visitCompilationUnit(CompilationUnit node) {
|
||||
_enclosingLibrary =
|
||||
@@ -2301,6 +2309,19 @@ class DirectiveResolver extends SimpleAstVisitor {
|
||||
for (ExportElement element in _enclosingLibrary.exports) {
|
||||
if (element.nameOffset == nodeOffset) {
|
||||
node.element = element;
|
||||
// Verify the exported source kind.
|
||||
Source exportedSource = element.exportedLibrary.source;
|
||||
int exportedTime = sourceModificationTimeMap[exportedSource] ?? -1;
|
||||
if (exportedTime >= 0 &&
|
||||
exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) {
|
||||
StringLiteral uriLiteral = node.uri;
|
||||
errors.add(new AnalysisError(
|
||||
_enclosingLibrary.source,
|
||||
uriLiteral.offset,
|
||||
uriLiteral.length,
|
||||
CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY,
|
||||
[uriLiteral.toSource()]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2313,6 +2334,22 @@ class DirectiveResolver extends SimpleAstVisitor {
|
||||
for (ImportElement element in _enclosingLibrary.imports) {
|
||||
if (element.nameOffset == nodeOffset) {
|
||||
node.element = element;
|
||||
// Verify the imported source kind.
|
||||
Source importedSource = element.importedLibrary.source;
|
||||
int importedTime = sourceModificationTimeMap[importedSource] ?? -1;
|
||||
if (importedTime >= 0 &&
|
||||
importSourceKindMap[importedSource] != SourceKind.LIBRARY) {
|
||||
StringLiteral uriLiteral = node.uri;
|
||||
ErrorCode errorCode = element.isDeferred
|
||||
? StaticWarningCode.IMPORT_OF_NON_LIBRARY
|
||||
: CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY;
|
||||
errors.add(new AnalysisError(
|
||||
_enclosingLibrary.source,
|
||||
uriLiteral.offset,
|
||||
uriLiteral.length,
|
||||
errorCode,
|
||||
[uriLiteral.toSource()]));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ const ResultCachingPolicy<UsedLocalElements> USED_LOCAL_ELEMENTS_POLICY =
|
||||
const SimpleResultCachingPolicy(-1, -1);
|
||||
|
||||
/**
|
||||
* The errors produced while resolving a library directives.
|
||||
* The errors produced while building a library's directives.
|
||||
*
|
||||
* The list will be empty if there were no errors, but will not be `null`.
|
||||
*
|
||||
@@ -125,7 +125,6 @@ const ResultCachingPolicy<UsedLocalElements> USED_LOCAL_ELEMENTS_POLICY =
|
||||
final ListResultDescriptor<AnalysisError> BUILD_DIRECTIVES_ERRORS =
|
||||
new ListResultDescriptor<AnalysisError>(
|
||||
'BUILD_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS);
|
||||
|
||||
/**
|
||||
* The errors produced while building a library element.
|
||||
*
|
||||
@@ -352,6 +351,7 @@ final List<ListResultDescriptor<AnalysisError>> ERROR_UNIT_RESULTS =
|
||||
HINTS,
|
||||
LIBRARY_UNIT_ERRORS,
|
||||
LINTS,
|
||||
RESOLVE_DIRECTIVES_ERRORS,
|
||||
RESOLVE_TYPE_BOUNDS_ERRORS,
|
||||
RESOLVE_TYPE_NAMES_ERRORS,
|
||||
RESOLVE_UNIT_ERRORS,
|
||||
@@ -704,6 +704,17 @@ final ListResultDescriptor<ConstantEvaluationTarget> REQUIRED_CONSTANTS =
|
||||
new ListResultDescriptor<ConstantEvaluationTarget>(
|
||||
'REQUIRED_CONSTANTS', const <ConstantEvaluationTarget>[]);
|
||||
|
||||
/**
|
||||
* The errors produced while resolving a library's directives.
|
||||
*
|
||||
* The list will be empty if there were no errors, but will not be `null`.
|
||||
*
|
||||
* The result is only available for [Source]s representing a library.
|
||||
*/
|
||||
final ListResultDescriptor<AnalysisError> RESOLVE_DIRECTIVES_ERRORS =
|
||||
new ListResultDescriptor<AnalysisError>(
|
||||
'RESOLVE_DIRECTIVES_ERRORS', AnalysisError.NO_ERRORS);
|
||||
|
||||
/**
|
||||
* The errors produced while resolving bounds of type parameters of classes,
|
||||
* class and function aliases.
|
||||
@@ -1232,8 +1243,10 @@ class BuildDirectiveElementsTask extends SourceBasedAnalysisTask {
|
||||
libraryElement.invalidateLibraryCycles();
|
||||
errors = builder.errors;
|
||||
} else {
|
||||
DirectiveResolver resolver = new DirectiveResolver();
|
||||
DirectiveResolver resolver = new DirectiveResolver(
|
||||
sourceModificationTimeMap, importSourceKindMap, exportSourceKindMap);
|
||||
libraryUnit.accept(resolver);
|
||||
errors = resolver.errors;
|
||||
}
|
||||
//
|
||||
// Record outputs.
|
||||
@@ -3867,6 +3880,12 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask {
|
||||
static const String STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT =
|
||||
'STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT';
|
||||
|
||||
/**
|
||||
* The name of the [RESOLVE_DIRECTIVES_ERRORS] input.
|
||||
*/
|
||||
static const String RESOLVE_DIRECTIVES_ERRORS_INPUT =
|
||||
'RESOLVE_DIRECTIVES_ERRORS';
|
||||
|
||||
/**
|
||||
* The name of the [STRONG_MODE_ERRORS] input.
|
||||
*/
|
||||
@@ -3925,6 +3944,7 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask {
|
||||
errorLists.add(getRequiredInput(BUILD_LIBRARY_ERRORS_INPUT));
|
||||
errorLists.add(getRequiredInput(HINTS_INPUT));
|
||||
errorLists.add(getRequiredInput(LINTS_INPUT));
|
||||
errorLists.add(getRequiredInput(RESOLVE_DIRECTIVES_ERRORS_INPUT));
|
||||
errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT));
|
||||
errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS2_INPUT));
|
||||
errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT));
|
||||
@@ -3948,6 +3968,7 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask {
|
||||
Map<String, TaskInput> inputs = <String, TaskInput>{
|
||||
HINTS_INPUT: HINTS.of(unit),
|
||||
LINTS_INPUT: LINTS.of(unit),
|
||||
RESOLVE_DIRECTIVES_ERRORS_INPUT: RESOLVE_DIRECTIVES_ERRORS.of(unit),
|
||||
RESOLVE_TYPE_NAMES_ERRORS_INPUT: RESOLVE_TYPE_NAMES_ERRORS.of(unit),
|
||||
RESOLVE_TYPE_NAMES_ERRORS2_INPUT: RESOLVE_TYPE_BOUNDS_ERRORS.of(unit),
|
||||
RESOLVE_UNIT_ERRORS_INPUT: RESOLVE_UNIT_ERRORS.of(unit),
|
||||
@@ -5017,14 +5038,22 @@ class ResolveDirectiveElementsTask extends SourceBasedAnalysisTask {
|
||||
*/
|
||||
static const String UNIT_INPUT = 'UNIT_INPUT';
|
||||
|
||||
static const String SOURCES_MODIFICATION_TIME_INPUT =
|
||||
'SOURCES_MODIFICATION_TIME_INPUT';
|
||||
static const String IMPORTS_SOURCE_KIND_INPUT = 'IMPORTS_SOURCE_KIND_INPUT';
|
||||
static const String EXPORTS_SOURCE_KIND_INPUT = 'EXPORTS_SOURCE_KIND_INPUT';
|
||||
|
||||
/**
|
||||
* The task descriptor describing this kind of task.
|
||||
*/
|
||||
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor(
|
||||
'ResolveDirectiveElementsTask',
|
||||
createTask,
|
||||
buildInputs,
|
||||
<ResultDescriptor>[CREATED_RESOLVED_UNIT2, RESOLVED_UNIT2]);
|
||||
buildInputs, <ResultDescriptor>[
|
||||
CREATED_RESOLVED_UNIT2,
|
||||
RESOLVED_UNIT2,
|
||||
RESOLVE_DIRECTIVES_ERRORS
|
||||
]);
|
||||
|
||||
ResolveDirectiveElementsTask(
|
||||
InternalAnalysisContext context, AnalysisTarget target)
|
||||
@@ -5040,18 +5069,28 @@ class ResolveDirectiveElementsTask extends SourceBasedAnalysisTask {
|
||||
// Prepare inputs.
|
||||
//
|
||||
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
|
||||
Map<Source, int> sourceModificationTimeMap =
|
||||
getRequiredInput(SOURCES_MODIFICATION_TIME_INPUT);
|
||||
Map<Source, SourceKind> importSourceKindMap =
|
||||
getRequiredInput(IMPORTS_SOURCE_KIND_INPUT);
|
||||
Map<Source, SourceKind> exportSourceKindMap =
|
||||
getRequiredInput(EXPORTS_SOURCE_KIND_INPUT);
|
||||
//
|
||||
// Resolve directive AST nodes to elements.
|
||||
//
|
||||
List<AnalysisError> errors = const <AnalysisError>[];
|
||||
if (targetUnit.unit == targetUnit.library) {
|
||||
DirectiveResolver resolver = new DirectiveResolver();
|
||||
DirectiveResolver resolver = new DirectiveResolver(
|
||||
sourceModificationTimeMap, importSourceKindMap, exportSourceKindMap);
|
||||
unit.accept(resolver);
|
||||
errors = resolver.errors;
|
||||
}
|
||||
//
|
||||
// Record outputs.
|
||||
//
|
||||
outputs[CREATED_RESOLVED_UNIT2] = true;
|
||||
outputs[RESOLVED_UNIT2] = unit;
|
||||
outputs[RESOLVE_DIRECTIVES_ERRORS] = errors;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -5063,7 +5102,13 @@ class ResolveDirectiveElementsTask extends SourceBasedAnalysisTask {
|
||||
LibrarySpecificUnit unit = target;
|
||||
return <String, TaskInput>{
|
||||
LIBRARY_INPUT: LIBRARY_ELEMENT2.of(unit.library),
|
||||
UNIT_INPUT: RESOLVED_UNIT1.of(unit)
|
||||
UNIT_INPUT: RESOLVED_UNIT1.of(unit),
|
||||
SOURCES_MODIFICATION_TIME_INPUT:
|
||||
REFERENCED_SOURCES.of(unit.library).toMapOf(MODIFICATION_TIME),
|
||||
IMPORTS_SOURCE_KIND_INPUT:
|
||||
IMPORTED_LIBRARIES.of(unit.library).toMapOf(SOURCE_KIND),
|
||||
EXPORTS_SOURCE_KIND_INPUT:
|
||||
EXPORTED_LIBRARIES.of(unit.library).toMapOf(SOURCE_KIND)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ class DartWorkManager implements WorkManager {
|
||||
HINTS,
|
||||
LINTS,
|
||||
LIBRARY_UNIT_ERRORS,
|
||||
RESOLVE_DIRECTIVES_ERRORS,
|
||||
RESOLVE_TYPE_NAMES_ERRORS,
|
||||
RESOLVE_TYPE_BOUNDS_ERRORS,
|
||||
RESOLVE_UNIT_ERRORS,
|
||||
|
||||
@@ -17,12 +17,6 @@ class CompileTimeErrorCodeTest_Driver extends CompileTimeErrorCodeTest {
|
||||
@override
|
||||
bool get enableNewAnalysisDriver => true;
|
||||
|
||||
@failingTest
|
||||
@override
|
||||
test_exportOfNonLibrary() {
|
||||
return super.test_exportOfNonLibrary();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@override
|
||||
test_fieldInitializerOutsideConstructor_inFunctionTypeParameter() {
|
||||
@@ -36,12 +30,6 @@ class CompileTimeErrorCodeTest_Driver extends CompileTimeErrorCodeTest {
|
||||
return super.test_fromEnvironment_bool_badDefault_whenDefined();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@override
|
||||
test_importOfNonLibrary() {
|
||||
return super.test_importOfNonLibrary();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@override
|
||||
test_nonConstValueInInitializer_assert_condition() {
|
||||
|
||||
@@ -22,10 +22,4 @@ class StaticWarningCodeTest_Driver extends StaticWarningCodeTest {
|
||||
test_argumentTypeNotAssignable_ambiguousClassName() {
|
||||
return super.test_argumentTypeNotAssignable_ambiguousClassName();
|
||||
}
|
||||
|
||||
@failingTest
|
||||
@override
|
||||
test_importOfNonLibrary() {
|
||||
return super.test_importOfNonLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user