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

Unified Diff: pkg/analyzer/lib/src/generated/constant.dart

Issue 1416873003: Rework handling of potentially-constant variables. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/constant.dart
diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
index c2ec01e730f6b64bf70a0e6302f23fda057511ae..5a3f445a88663d845a7ece8f9f7e73be88c1c5ba 100644
--- a/pkg/analyzer/lib/src/generated/constant.dart
+++ b/pkg/analyzer/lib/src/generated/constant.dart
@@ -320,23 +320,21 @@ class ConstantEvaluationEngine {
*/
void computeConstantValue(ConstantEvaluationTarget constant) {
validator.beforeComputeValue(constant);
- if (constant is ParameterElement) {
+ if (constant is ParameterElementImpl) {
if (constant.initializer != null) {
- Expression defaultValue =
- (constant as PotentiallyConstVariableElement).constantInitializer;
+ Expression defaultValue = constant.constantInitializer;
if (defaultValue != null) {
RecordingErrorListener errorListener = new RecordingErrorListener();
ErrorReporter errorReporter =
new ErrorReporter(errorListener, constant.source);
DartObjectImpl dartObject =
defaultValue.accept(new ConstantVisitor(this, errorReporter));
- (constant as ParameterElementImpl).evaluationResult =
+ constant.evaluationResult =
new EvaluationResultImpl(dartObject, errorListener.errors);
}
}
- } else if (constant is VariableElement) {
- Expression constantInitializer =
- (constant as PotentiallyConstVariableElement).constantInitializer;
+ } else if (constant is VariableElementImpl) {
+ Expression constantInitializer = constant.constantInitializer;
if (constantInitializer != null) {
RecordingErrorListener errorListener = new RecordingErrorListener();
ErrorReporter errorReporter =
@@ -355,7 +353,7 @@ class ConstantEvaluationEngine {
[dartObject.type, constant.type]);
}
}
- (constant as VariableElementImpl).evaluationResult =
+ constant.evaluationResult =
new EvaluationResultImpl(dartObject, errorListener.errors);
}
} else if (constant is ConstructorElement) {
@@ -415,6 +413,12 @@ class ConstantEvaluationEngine {
elementAnnotation.evaluationResult = new EvaluationResultImpl(null);
}
}
+ } else if (constant is VariableElement) {
+ // constant is a VariableElement but not a VariableElementImpl. This can
+ // happen sometimes in the case of invalid user code (for example, a
+ // constant expression that refers to a nonstatic field inside a generic
+ // class will wind up referring to a FieldMember). The error is detected
+ // elsewhere, so just silently ignore it here.
} else {
// Should not happen.
assert(false);
@@ -439,15 +443,14 @@ class ConstantEvaluationEngine {
void computeDependencies(
ConstantEvaluationTarget constant, ReferenceFinderCallback callback) {
ReferenceFinder referenceFinder = new ReferenceFinder(callback);
- if (constant is ParameterElement) {
+ if (constant is ParameterElementImpl) {
if (constant.initializer != null) {
- Expression defaultValue =
- (constant as ConstVariableElement).constantInitializer;
+ Expression defaultValue = constant.constantInitializer;
if (defaultValue != null) {
defaultValue.accept(referenceFinder);
}
}
- } else if (constant is PotentiallyConstVariableElement) {
+ } else if (constant is VariableElementImpl) {
Expression initializer = constant.constantInitializer;
if (initializer != null) {
initializer.accept(referenceFinder);
@@ -532,6 +535,12 @@ class ConstantEvaluationEngine {
if (constNode.arguments != null) {
constNode.arguments.accept(referenceFinder);
}
+ } else if (constant is VariableElement) {
+ // constant is a VariableElement but not a VariableElementImpl. This can
+ // happen sometimes in the case of invalid user code (for example, a
+ // constant expression that refers to a nonstatic field inside a generic
+ // class will wind up referring to a FieldMember). So just don't bother
+ // computing any dependencies.
} else {
// Should not happen.
assert(false);
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/generated/element.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698