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

Unified Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1145913002: In constant evaluation, handle annotation referring to non-const constructor. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 7 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 | « pkg/analyzer/lib/src/generated/constant.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/src/task/dart_test.dart
diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart
index aff479b2bdedd620a4b9555893a8e22cd310e197..a44021e38ce3858c2cf9d2fe27531247ac4de6e2 100644
--- a/pkg/analyzer/test/src/task/dart_test.dart
+++ b/pkg/analyzer/test/src/task/dart_test.dart
@@ -1312,6 +1312,28 @@ class ComputeConstantValueTaskTest extends _AbstractDartTaskTest {
return null;
}
+ test_annotation_non_const_constructor() {
+ // Calling a non-const constructor from an annotation that is illegal, but
+ // shouldn't crash analysis.
+ Source source = newSource('/test.dart', '''
+class A {
+ final int i;
+ A(this.i);
+}
+
+@A(5)
+class C {}
+''');
+ // First compute the resolved unit for the source.
+ CompilationUnit unit = _resolveSource(source);
+ // Compute the constant value of the annotation on C.
+ EvaluationResultImpl evaluationResult =
+ computeClassAnnotation(source, unit, 'C');
+ // And check that it has no value stored in it.
+ expect(evaluationResult, isNotNull);
+ expect(evaluationResult.value, isNull);
+ }
+
test_annotation_with_args() {
Source source = newSource('/test.dart', '''
const x = 1;
@@ -1322,10 +1344,7 @@ class D {
}
''');
// First compute the resolved unit for the source.
- LibrarySpecificUnit librarySpecificUnit =
- new LibrarySpecificUnit(source, source);
- _computeResult(librarySpecificUnit, RESOLVED_UNIT1);
- CompilationUnit unit = outputs[RESOLVED_UNIT1];
+ CompilationUnit unit = _resolveSource(source);
// Compute the constant value of the annotation on C.
EvaluationResultImpl evaluationResult =
computeClassAnnotation(source, unit, 'C');
@@ -1344,10 +1363,7 @@ const x = 1;
@x class C {}
''');
// First compute the resolved unit for the source.
- LibrarySpecificUnit librarySpecificUnit =
- new LibrarySpecificUnit(source, source);
- _computeResult(librarySpecificUnit, RESOLVED_UNIT1);
- CompilationUnit unit = outputs[RESOLVED_UNIT1];
+ CompilationUnit unit = _resolveSource(source);
// Compute the constant value of the annotation on C.
EvaluationResultImpl evaluationResult =
computeClassAnnotation(source, unit, 'C');
@@ -1462,15 +1478,16 @@ const x = 1;
(TopLevelVariableElement variable) => variable.name == variableName);
}
- CompilationUnit _resolveUnit(String content) {
- Source source = newSource('/test.dart', content);
- // First compute the resolved unit for the source.
+ CompilationUnit _resolveSource(Source source) {
LibrarySpecificUnit librarySpecificUnit =
new LibrarySpecificUnit(source, source);
_computeResult(librarySpecificUnit, RESOLVED_UNIT1);
CompilationUnit unit = outputs[RESOLVED_UNIT1];
return unit;
}
+
+ CompilationUnit _resolveUnit(String content) =>
+ _resolveSource(newSource('/test.dart', content));
}
@reflectiveTest
« no previous file with comments | « pkg/analyzer/lib/src/generated/constant.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698