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

Unified Diff: pkg/analyzer/test/src/summary/summary_common.dart

Issue 1864753002: Use isValidConst flag to distinguish between const / final expressions. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
Index: pkg/analyzer/test/src/summary/summary_common.dart
diff --git a/pkg/analyzer/test/src/summary/summary_common.dart b/pkg/analyzer/test/src/summary/summary_common.dart
index 49ae53d6eee1888f50e818953d0e44ccb08e46b6..8b350e778ba003bcbb8957229c654d71b277a517 100644
--- a/pkg/analyzer/test/src/summary/summary_common.dart
+++ b/pkg/analyzer/test/src/summary/summary_common.dart
@@ -5957,7 +5957,7 @@ class C {
A a = new A();
final v = (a.b.c.f[1] = 5);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.pushReference,
UnlinkedConstOperation.pushInt,
@@ -5996,7 +5996,7 @@ class C {
A a = new A();
final v = (a.b[1].c[2].f[3] = 5);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
// 5
UnlinkedConstOperation.pushInt,
// a.b[1]
@@ -6037,7 +6037,7 @@ final v = (a.b[1].c[2].f[3] = 5);
List<int> a = <int>[0, 1, 2];
final v = (a[1] = 5);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.pushReference,
UnlinkedConstOperation.pushInt,
@@ -6063,7 +6063,7 @@ class C {
}
final v = (new C().f = 5);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.invokeConstructor,
UnlinkedConstOperation.assignToProperty,
@@ -6091,7 +6091,7 @@ class C {
}
final v = (C.f = 1);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.assignToRef,
], assignmentOperators: [
@@ -6124,7 +6124,7 @@ class C {
A a = new A();
final v = (a.b.c.f = 1);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.assignToRef,
], assignmentOperators: [
@@ -6171,7 +6171,7 @@ final v = (a.b.c.f = 1);
int a = 0;
final v = (a = 1);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.assignToRef,
], assignmentOperators: [
@@ -6197,7 +6197,7 @@ int a = 0;
import 'a.dart';
final v = (a = 1);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.assignToRef,
], assignmentOperators: [
@@ -6223,7 +6223,7 @@ int a = 0;
import 'a.dart' as p;
final v = (p.a = 1);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.assignToRef,
], assignmentOperators: [
@@ -6239,6 +6239,41 @@ final v = (p.a = 1);
]);
}
+ test_expr_cascadeSection_assignToIndex() {
+ if (skipNonConstInitializers) {
+ return;
+ }
+ UnlinkedVariable variable = serializeVariableText('''
+class C {
+ List<int> items;
+}
+final C c = new C();
+final v = c.items..[1] = 2;
+''');
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
+ UnlinkedConstOperation.pushReference,
+ // ..[1] = 2
+ UnlinkedConstOperation.cascadeSectionBegin,
+ UnlinkedConstOperation.pushInt,
+ UnlinkedConstOperation.pushInt,
+ UnlinkedConstOperation.assignToIndex,
+ // c
+ UnlinkedConstOperation.cascadeSectionEnd,
+ ], assignmentOperators: [
+ UnlinkedExprAssignOperator.assign,
+ ], ints: [
+ 2,
+ 1
+ ], strings: [], referenceValidators: [
+ (EntityRef r) => checkTypeRef(r, null, null, 'items',
+ expectedKind: ReferenceKind.unresolved,
+ prefixExpectations: [
+ new _PrefixExpectation(
+ ReferenceKind.topLevelPropertyAccessor, 'c'),
+ ])
+ ]);
+ }
+
test_expr_cascadeSection_assignToProperty() {
if (skipNonConstInitializers) {
return;
@@ -6250,7 +6285,7 @@ class C {
}
final v = new C()..f1 = 1..f2 += 2;
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
// new C()
UnlinkedConstOperation.invokeConstructor,
// ..f1 = 1
@@ -6281,41 +6316,6 @@ final v = new C()..f1 = 1..f2 += 2;
]);
}
- test_expr_cascadeSection_assignToIndex() {
- if (skipNonConstInitializers) {
- return;
- }
- UnlinkedVariable variable = serializeVariableText('''
-class C {
- List<int> items;
-}
-final C c = new C();
-final v = c.items..[1] = 2;
-''');
- _assertUnlinkedConst(variable.constExpr, operators: [
- UnlinkedConstOperation.pushReference,
- // ..[1] = 2
- UnlinkedConstOperation.cascadeSectionBegin,
- UnlinkedConstOperation.pushInt,
- UnlinkedConstOperation.pushInt,
- UnlinkedConstOperation.assignToIndex,
- // c
- UnlinkedConstOperation.cascadeSectionEnd,
- ], assignmentOperators: [
- UnlinkedExprAssignOperator.assign,
- ], ints: [
- 2,
- 1
- ], strings: [], referenceValidators: [
- (EntityRef r) => checkTypeRef(r, null, null, 'items',
- expectedKind: ReferenceKind.unresolved,
- prefixExpectations: [
- new _PrefixExpectation(
- ReferenceKind.topLevelPropertyAccessor, 'c'),
- ])
- ]);
- }
-
test_expr_cascadeSection_embedded() {
if (skipNonConstInitializers) {
return;
@@ -6334,7 +6334,7 @@ final v = new A()
..b = (new B()..fb = 2)
..fa2 = 3;
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
// new A()
UnlinkedConstOperation.invokeConstructor,
// ..fa1 = 1
@@ -6396,7 +6396,7 @@ class A {
final A a = new A();
final v = a..m(5).abs()..m(6);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
// a
UnlinkedConstOperation.pushReference,
// ..m(5)
@@ -6437,7 +6437,7 @@ class C {
}
final v = new C().items[5];
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.invokeConstructor,
UnlinkedConstOperation.extractProperty,
UnlinkedConstOperation.pushInt,
@@ -6464,7 +6464,7 @@ class C {
}
final v = new C().f;
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.invokeConstructor,
UnlinkedConstOperation.extractProperty,
], ints: [
@@ -6488,7 +6488,7 @@ class C {
}
final v = new C().m(1, b: 2, c: 3);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.invokeConstructor,
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.pushInt,
@@ -6529,7 +6529,7 @@ class C {
A a = new A();
final v = a.b.c.m(10, 20);
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.invokeMethodRef,
@@ -6565,7 +6565,7 @@ class C {
import 'a.dart' as p;
final v = p.C.m();
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.invokeMethodRef,
], ints: [
0,
@@ -6629,7 +6629,7 @@ class C {
static int m() => 42;
}''').fields[0];
expect(variable.isFinal, isTrue);
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.invokeMethodRef,
UnlinkedConstOperation.add,
@@ -9038,7 +9038,7 @@ var v;''';
int a = 0;
final v = $expr;
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.add,
@@ -9099,7 +9099,7 @@ final v = $expr;
int a = 0;
final v = $expr;
''');
- _assertUnlinkedConst(variable.constExpr, operators: [
+ _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [
UnlinkedConstOperation.assignToRef,
UnlinkedConstOperation.pushInt,
UnlinkedConstOperation.add,
@@ -9117,7 +9117,7 @@ final v = $expr;
* TODO(scheglov) rename "Const" to "Expr" everywhere
*/
void _assertUnlinkedConst(UnlinkedConst constExpr,
- {bool isInvalid: false,
+ {bool isValidConst: true,
List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[],
List<UnlinkedExprAssignOperator> assignmentOperators:
const <UnlinkedExprAssignOperator>[],
@@ -9127,7 +9127,7 @@ final v = $expr;
List<_EntityRefValidator> referenceValidators:
const <_EntityRefValidator>[]}) {
expect(constExpr, isNotNull);
- expect(constExpr.isInvalid, isInvalid);
+ expect(constExpr.isValidConst, isValidConst);
expect(constExpr.operations, operators);
expect(constExpr.ints, ints);
expect(constExpr.doubles, doubles);

Powered by Google App Engine
This is Rietveld 408576698