Index: pkg/analyzer/lib/src/task/dart.dart |
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart |
index b1349810a480c5bad2c81272fc857ce257d35a36..3596cdff42f3a60d518939881187f961b0f8b667 100644 |
--- a/pkg/analyzer/lib/src/task/dart.dart |
+++ b/pkg/analyzer/lib/src/task/dart.dart |
@@ -956,6 +956,28 @@ final ListResultDescriptor<AnalysisError> SCAN_ERRORS = |
'SCAN_ERRORS', AnalysisError.NO_ERRORS); |
/** |
+ * The errors produced while resolving a static [VariableElement] initializer. |
+ * |
+ * The result is only available for [VariableElement]s, and only when strong |
+ * mode is enabled. |
+ */ |
+final ListResultDescriptor<AnalysisError> STATIC_VARIABLE_RESOLUTION_ERRORS = |
+ new ListResultDescriptor<AnalysisError>( |
+ 'STATIC_VARIABLE_RESOLUTION_ERRORS', AnalysisError.NO_ERRORS); |
+ |
+/** |
+ * A list of the [AnalysisError]s reported while resolving static |
+ * [INFERABLE_STATIC_VARIABLES_IN_UNIT] defined in a unit. |
+ * |
+ * The result is only available for [LibrarySpecificUnit]s, and only when strong |
+ * mode is enabled. |
+ */ |
+final ListResultDescriptor<AnalysisError> |
+ STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT = |
+ new ListResultDescriptor<AnalysisError>( |
+ 'STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT', null); |
+ |
+/** |
* The additional strong mode errors produced while verifying a |
* compilation unit. |
* |
@@ -3627,10 +3649,10 @@ class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask { |
static const String UNIT_INPUT = 'UNIT_INPUT'; |
/** |
- * The name of the input whose value is a list of the inferable static |
- * variables whose types have been computed. |
+ * The name of the [STATIC_VARIABLE_RESOLUTION_ERRORS] for all static |
+ * variables in the compilation unit. |
*/ |
- static const String INFERRED_VARIABLES_INPUT = 'INFERRED_VARIABLES_INPUT'; |
+ static const String ERRORS_LIST_INPUT = 'INFERRED_VARIABLES_INPUT'; |
/** |
* The task descriptor describing this kind of task. |
@@ -3638,8 +3660,11 @@ class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask { |
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
'InferStaticVariableTypesInUnitTask', |
createTask, |
- buildInputs, |
- <ResultDescriptor>[CREATED_RESOLVED_UNIT9, RESOLVED_UNIT9]); |
+ buildInputs, <ResultDescriptor>[ |
+ CREATED_RESOLVED_UNIT9, |
+ RESOLVED_UNIT9, |
+ STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT |
+ ]); |
/** |
* Initialize a newly created task to build a library element for the given |
@@ -3658,6 +3683,7 @@ class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask { |
// Prepare inputs. |
// |
CompilationUnit unit = getRequiredInput(UNIT_INPUT); |
+ List<List<AnalysisError>> errorLists = getRequiredInput(ERRORS_LIST_INPUT); |
// |
// Record outputs. There is no additional work to be done at this time |
// because the work has implicitly been done by virtue of the task model |
@@ -3665,6 +3691,8 @@ class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask { |
// |
outputs[RESOLVED_UNIT9] = unit; |
outputs[CREATED_RESOLVED_UNIT9] = true; |
+ outputs[STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] = |
+ AnalysisError.mergeLists(errorLists); |
} |
/** |
@@ -3675,9 +3703,12 @@ class InferStaticVariableTypesInUnitTask extends SourceBasedAnalysisTask { |
static Map<String, TaskInput> buildInputs(AnalysisTarget target) { |
LibrarySpecificUnit unit = target; |
return <String, TaskInput>{ |
- INFERRED_VARIABLES_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT |
+ 'inferredTypes': INFERABLE_STATIC_VARIABLES_IN_UNIT |
.of(unit) |
.toListOf(INFERRED_STATIC_VARIABLE), |
+ ERRORS_LIST_INPUT: INFERABLE_STATIC_VARIABLES_IN_UNIT |
+ .of(unit) |
+ .toListOf(STATIC_VARIABLE_RESOLUTION_ERRORS), |
UNIT_INPUT: RESOLVED_UNIT8.of(unit) |
}; |
} |
@@ -3716,8 +3747,10 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask { |
static final TaskDescriptor DESCRIPTOR = new TaskDescriptor( |
'InferStaticVariableTypeTask', |
createTask, |
- buildInputs, |
- <ResultDescriptor>[INFERRED_STATIC_VARIABLE]); |
+ buildInputs, <ResultDescriptor>[ |
+ INFERRED_STATIC_VARIABLE, |
+ STATIC_VARIABLE_RESOLUTION_ERRORS |
+ ]); |
InferStaticVariableTypeTask( |
InternalAnalysisContext context, VariableElement variable) |
@@ -3745,17 +3778,19 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask { |
// If we're not in a dependency cycle, and we have no type annotation, |
// re-resolve the right hand side and do inference. |
+ List<AnalysisError> errors = AnalysisError.NO_ERRORS; |
if (dependencyCycle == null && variable.hasImplicitType) { |
VariableDeclaration declaration = getDeclaration(unit); |
// |
// Re-resolve the variable's initializer so that the inferred types |
// of other variables will be propagated. |
// |
+ RecordingErrorListener errorListener = new RecordingErrorListener(); |
Expression initializer = declaration.initializer; |
ResolutionContext resolutionContext = ResolutionContextBuilder.contextFor( |
initializer, AnalysisErrorListener.NULL_LISTENER); |
- ResolverVisitor visitor = new ResolverVisitor(variable.library, |
- variable.source, typeProvider, AnalysisErrorListener.NULL_LISTENER, |
+ ResolverVisitor visitor = new ResolverVisitor( |
+ variable.library, variable.source, typeProvider, errorListener, |
nameScope: resolutionContext.scope); |
if (resolutionContext.enclosingClassDeclaration != null) { |
visitor.prepareToResolveMembersInClass( |
@@ -3772,6 +3807,7 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask { |
newType = typeProvider.dynamicType; |
} |
setFieldType(variable, newType); |
+ errors = getUniqueErrors(errorListener.errors); |
} else { |
// TODO(brianwilkerson) For now we simply don't infer any type for |
// variables or fields involved in a cycle. We could try to be smarter |
@@ -3784,6 +3820,7 @@ class InferStaticVariableTypeTask extends InferStaticVariableTask { |
// Record outputs. |
// |
outputs[INFERRED_STATIC_VARIABLE] = variable; |
+ outputs[STATIC_VARIABLE_RESOLUTION_ERRORS] = errors; |
} |
/** |
@@ -3898,6 +3935,12 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { |
static const String LINTS_INPUT = 'LINTS'; |
/** |
+ * The name of the [STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT] input. |
+ */ |
+ static const String STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT = |
+ 'STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT'; |
+ |
+ /** |
* The name of the [STRONG_MODE_ERRORS] input. |
*/ |
static const String STRONG_MODE_ERRORS_INPUT = 'STRONG_MODE_ERRORS'; |
@@ -3958,6 +4001,7 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { |
errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS_INPUT)); |
errorLists.add(getRequiredInput(RESOLVE_TYPE_NAMES_ERRORS2_INPUT)); |
errorLists.add(getRequiredInput(RESOLVE_UNIT_ERRORS_INPUT)); |
+ errorLists.add(getRequiredInput(STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT)); |
errorLists.add(getRequiredInput(STRONG_MODE_ERRORS_INPUT)); |
errorLists.add(getRequiredInput(VARIABLE_REFERENCE_ERRORS_INPUT)); |
errorLists.add(getRequiredInput(VERIFY_ERRORS_INPUT)); |
@@ -3980,6 +4024,8 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { |
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), |
+ STATIC_VARIABLE_RESOLUTION_ERRORS_INPUT: |
+ STATIC_VARIABLE_RESOLUTION_ERRORS_IN_UNIT.of(unit), |
STRONG_MODE_ERRORS_INPUT: STRONG_MODE_ERRORS.of(unit), |
VARIABLE_REFERENCE_ERRORS_INPUT: VARIABLE_REFERENCE_ERRORS.of(unit), |
VERIFY_ERRORS_INPUT: VERIFY_ERRORS.of(unit) |
@@ -4008,6 +4054,14 @@ class LibraryUnitErrorsTask extends SourceBasedAnalysisTask { |
} |
} |
+class MyErrorListener implements AnalysisErrorListener { |
Jennifer Messerly
2016/08/11 13:39:37
was this for debugging?
|
+ @override |
+ void onError(AnalysisError error) { |
+ print('onError: $error'); |
+ // TODO: implement onError |
+ } |
+} |
+ |
/** |
* A task that parses the content of a Dart file, producing an AST structure, |
* any lexical errors found in the process, the kind of the file (library or |