| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.summary.summary_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 5939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5950 } | 5950 } |
| 5951 class B { | 5951 class B { |
| 5952 C c; | 5952 C c; |
| 5953 } | 5953 } |
| 5954 class C { | 5954 class C { |
| 5955 List<int> f = <int>[0, 1, 2]; | 5955 List<int> f = <int>[0, 1, 2]; |
| 5956 } | 5956 } |
| 5957 A a = new A(); | 5957 A a = new A(); |
| 5958 final v = (a.b.c.f[1] = 5); | 5958 final v = (a.b.c.f[1] = 5); |
| 5959 '''); | 5959 '''); |
| 5960 _assertUnlinkedConst(variable.constExpr, operators: [ | 5960 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 5961 UnlinkedConstOperation.pushInt, | 5961 UnlinkedConstOperation.pushInt, |
| 5962 UnlinkedConstOperation.pushReference, | 5962 UnlinkedConstOperation.pushReference, |
| 5963 UnlinkedConstOperation.pushInt, | 5963 UnlinkedConstOperation.pushInt, |
| 5964 UnlinkedConstOperation.assignToIndex, | 5964 UnlinkedConstOperation.assignToIndex, |
| 5965 ], assignmentOperators: [ | 5965 ], assignmentOperators: [ |
| 5966 (UnlinkedExprAssignOperator.assign) | 5966 (UnlinkedExprAssignOperator.assign) |
| 5967 ], ints: [ | 5967 ], ints: [ |
| 5968 5, | 5968 5, |
| 5969 1 | 5969 1 |
| 5970 ], strings: [], referenceValidators: [ | 5970 ], strings: [], referenceValidators: [ |
| (...skipping 18 matching lines...) Expand all Loading... |
| 5989 } | 5989 } |
| 5990 class B { | 5990 class B { |
| 5991 List<C> c; | 5991 List<C> c; |
| 5992 } | 5992 } |
| 5993 class C { | 5993 class C { |
| 5994 List<int> f = <int>[0, 1, 2]; | 5994 List<int> f = <int>[0, 1, 2]; |
| 5995 } | 5995 } |
| 5996 A a = new A(); | 5996 A a = new A(); |
| 5997 final v = (a.b[1].c[2].f[3] = 5); | 5997 final v = (a.b[1].c[2].f[3] = 5); |
| 5998 '''); | 5998 '''); |
| 5999 _assertUnlinkedConst(variable.constExpr, operators: [ | 5999 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6000 // 5 | 6000 // 5 |
| 6001 UnlinkedConstOperation.pushInt, | 6001 UnlinkedConstOperation.pushInt, |
| 6002 // a.b[1] | 6002 // a.b[1] |
| 6003 UnlinkedConstOperation.pushReference, | 6003 UnlinkedConstOperation.pushReference, |
| 6004 UnlinkedConstOperation.pushInt, | 6004 UnlinkedConstOperation.pushInt, |
| 6005 UnlinkedConstOperation.extractIndex, | 6005 UnlinkedConstOperation.extractIndex, |
| 6006 // c[2] | 6006 // c[2] |
| 6007 UnlinkedConstOperation.extractProperty, | 6007 UnlinkedConstOperation.extractProperty, |
| 6008 UnlinkedConstOperation.pushInt, | 6008 UnlinkedConstOperation.pushInt, |
| 6009 UnlinkedConstOperation.extractIndex, | 6009 UnlinkedConstOperation.extractIndex, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6030 } | 6030 } |
| 6031 | 6031 |
| 6032 test_expr_assignToIndex_ofTopLevelVariable() { | 6032 test_expr_assignToIndex_ofTopLevelVariable() { |
| 6033 if (skipNonConstInitializers) { | 6033 if (skipNonConstInitializers) { |
| 6034 return; | 6034 return; |
| 6035 } | 6035 } |
| 6036 UnlinkedVariable variable = serializeVariableText(''' | 6036 UnlinkedVariable variable = serializeVariableText(''' |
| 6037 List<int> a = <int>[0, 1, 2]; | 6037 List<int> a = <int>[0, 1, 2]; |
| 6038 final v = (a[1] = 5); | 6038 final v = (a[1] = 5); |
| 6039 '''); | 6039 '''); |
| 6040 _assertUnlinkedConst(variable.constExpr, operators: [ | 6040 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6041 UnlinkedConstOperation.pushInt, | 6041 UnlinkedConstOperation.pushInt, |
| 6042 UnlinkedConstOperation.pushReference, | 6042 UnlinkedConstOperation.pushReference, |
| 6043 UnlinkedConstOperation.pushInt, | 6043 UnlinkedConstOperation.pushInt, |
| 6044 UnlinkedConstOperation.assignToIndex, | 6044 UnlinkedConstOperation.assignToIndex, |
| 6045 ], assignmentOperators: [ | 6045 ], assignmentOperators: [ |
| 6046 (UnlinkedExprAssignOperator.assign) | 6046 (UnlinkedExprAssignOperator.assign) |
| 6047 ], ints: [ | 6047 ], ints: [ |
| 6048 5, | 6048 5, |
| 6049 1, | 6049 1, |
| 6050 ], strings: [], referenceValidators: [ | 6050 ], strings: [], referenceValidators: [ |
| 6051 (EntityRef r) => checkTypeRef(r, null, null, 'a', | 6051 (EntityRef r) => checkTypeRef(r, null, null, 'a', |
| 6052 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 6052 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 6053 ]); | 6053 ]); |
| 6054 } | 6054 } |
| 6055 | 6055 |
| 6056 test_expr_assignToProperty_ofInstanceCreation() { | 6056 test_expr_assignToProperty_ofInstanceCreation() { |
| 6057 if (skipNonConstInitializers) { | 6057 if (skipNonConstInitializers) { |
| 6058 return; | 6058 return; |
| 6059 } | 6059 } |
| 6060 UnlinkedVariable variable = serializeVariableText(''' | 6060 UnlinkedVariable variable = serializeVariableText(''' |
| 6061 class C { | 6061 class C { |
| 6062 int f; | 6062 int f; |
| 6063 } | 6063 } |
| 6064 final v = (new C().f = 5); | 6064 final v = (new C().f = 5); |
| 6065 '''); | 6065 '''); |
| 6066 _assertUnlinkedConst(variable.constExpr, operators: [ | 6066 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6067 UnlinkedConstOperation.pushInt, | 6067 UnlinkedConstOperation.pushInt, |
| 6068 UnlinkedConstOperation.invokeConstructor, | 6068 UnlinkedConstOperation.invokeConstructor, |
| 6069 UnlinkedConstOperation.assignToProperty, | 6069 UnlinkedConstOperation.assignToProperty, |
| 6070 ], assignmentOperators: [ | 6070 ], assignmentOperators: [ |
| 6071 (UnlinkedExprAssignOperator.assign) | 6071 (UnlinkedExprAssignOperator.assign) |
| 6072 ], ints: [ | 6072 ], ints: [ |
| 6073 5, | 6073 5, |
| 6074 0, | 6074 0, |
| 6075 0, | 6075 0, |
| 6076 ], strings: [ | 6076 ], strings: [ |
| 6077 'f' | 6077 'f' |
| 6078 ], referenceValidators: [ | 6078 ], referenceValidators: [ |
| 6079 (EntityRef r) => checkTypeRef(r, null, null, 'C', | 6079 (EntityRef r) => checkTypeRef(r, null, null, 'C', |
| 6080 expectedKind: ReferenceKind.classOrEnum) | 6080 expectedKind: ReferenceKind.classOrEnum) |
| 6081 ]); | 6081 ]); |
| 6082 } | 6082 } |
| 6083 | 6083 |
| 6084 test_expr_assignToRef_classStaticField() { | 6084 test_expr_assignToRef_classStaticField() { |
| 6085 if (skipNonConstInitializers) { | 6085 if (skipNonConstInitializers) { |
| 6086 return; | 6086 return; |
| 6087 } | 6087 } |
| 6088 UnlinkedVariable variable = serializeVariableText(''' | 6088 UnlinkedVariable variable = serializeVariableText(''' |
| 6089 class C { | 6089 class C { |
| 6090 static int f; | 6090 static int f; |
| 6091 } | 6091 } |
| 6092 final v = (C.f = 1); | 6092 final v = (C.f = 1); |
| 6093 '''); | 6093 '''); |
| 6094 _assertUnlinkedConst(variable.constExpr, operators: [ | 6094 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6095 UnlinkedConstOperation.pushInt, | 6095 UnlinkedConstOperation.pushInt, |
| 6096 UnlinkedConstOperation.assignToRef, | 6096 UnlinkedConstOperation.assignToRef, |
| 6097 ], assignmentOperators: [ | 6097 ], assignmentOperators: [ |
| 6098 (UnlinkedExprAssignOperator.assign) | 6098 (UnlinkedExprAssignOperator.assign) |
| 6099 ], ints: [ | 6099 ], ints: [ |
| 6100 1, | 6100 1, |
| 6101 ], strings: [], referenceValidators: [ | 6101 ], strings: [], referenceValidators: [ |
| 6102 (EntityRef r) => checkTypeRef(r, null, null, 'f', | 6102 (EntityRef r) => checkTypeRef(r, null, null, 'f', |
| 6103 expectedKind: ReferenceKind.unresolved, | 6103 expectedKind: ReferenceKind.unresolved, |
| 6104 prefixExpectations: [ | 6104 prefixExpectations: [ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 6117 } | 6117 } |
| 6118 class B { | 6118 class B { |
| 6119 C c; | 6119 C c; |
| 6120 } | 6120 } |
| 6121 class C { | 6121 class C { |
| 6122 int f; | 6122 int f; |
| 6123 } | 6123 } |
| 6124 A a = new A(); | 6124 A a = new A(); |
| 6125 final v = (a.b.c.f = 1); | 6125 final v = (a.b.c.f = 1); |
| 6126 '''); | 6126 '''); |
| 6127 _assertUnlinkedConst(variable.constExpr, operators: [ | 6127 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6128 UnlinkedConstOperation.pushInt, | 6128 UnlinkedConstOperation.pushInt, |
| 6129 UnlinkedConstOperation.assignToRef, | 6129 UnlinkedConstOperation.assignToRef, |
| 6130 ], assignmentOperators: [ | 6130 ], assignmentOperators: [ |
| 6131 (UnlinkedExprAssignOperator.assign) | 6131 (UnlinkedExprAssignOperator.assign) |
| 6132 ], ints: [ | 6132 ], ints: [ |
| 6133 1, | 6133 1, |
| 6134 ], strings: [], referenceValidators: [ | 6134 ], strings: [], referenceValidators: [ |
| 6135 (EntityRef r) => checkTypeRef(r, null, null, 'f', | 6135 (EntityRef r) => checkTypeRef(r, null, null, 'f', |
| 6136 expectedKind: ReferenceKind.unresolved, | 6136 expectedKind: ReferenceKind.unresolved, |
| 6137 prefixExpectations: [ | 6137 prefixExpectations: [ |
| (...skipping 26 matching lines...) Expand all Loading... |
| 6164 } | 6164 } |
| 6165 | 6165 |
| 6166 test_expr_assignToRef_topLevelVariable() { | 6166 test_expr_assignToRef_topLevelVariable() { |
| 6167 if (skipNonConstInitializers) { | 6167 if (skipNonConstInitializers) { |
| 6168 return; | 6168 return; |
| 6169 } | 6169 } |
| 6170 UnlinkedVariable variable = serializeVariableText(''' | 6170 UnlinkedVariable variable = serializeVariableText(''' |
| 6171 int a = 0; | 6171 int a = 0; |
| 6172 final v = (a = 1); | 6172 final v = (a = 1); |
| 6173 '''); | 6173 '''); |
| 6174 _assertUnlinkedConst(variable.constExpr, operators: [ | 6174 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6175 UnlinkedConstOperation.pushInt, | 6175 UnlinkedConstOperation.pushInt, |
| 6176 UnlinkedConstOperation.assignToRef, | 6176 UnlinkedConstOperation.assignToRef, |
| 6177 ], assignmentOperators: [ | 6177 ], assignmentOperators: [ |
| 6178 (UnlinkedExprAssignOperator.assign) | 6178 (UnlinkedExprAssignOperator.assign) |
| 6179 ], ints: [ | 6179 ], ints: [ |
| 6180 1, | 6180 1, |
| 6181 ], strings: [], referenceValidators: [ | 6181 ], strings: [], referenceValidators: [ |
| 6182 (EntityRef r) => checkTypeRef(r, null, null, 'a', | 6182 (EntityRef r) => checkTypeRef(r, null, null, 'a', |
| 6183 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 6183 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 6184 ]); | 6184 ]); |
| 6185 } | 6185 } |
| 6186 | 6186 |
| 6187 test_expr_assignToRef_topLevelVariable_imported() { | 6187 test_expr_assignToRef_topLevelVariable_imported() { |
| 6188 if (skipNonConstInitializers) { | 6188 if (skipNonConstInitializers) { |
| 6189 return; | 6189 return; |
| 6190 } | 6190 } |
| 6191 addNamedSource( | 6191 addNamedSource( |
| 6192 '/a.dart', | 6192 '/a.dart', |
| 6193 ''' | 6193 ''' |
| 6194 int a = 0; | 6194 int a = 0; |
| 6195 '''); | 6195 '''); |
| 6196 UnlinkedVariable variable = serializeVariableText(''' | 6196 UnlinkedVariable variable = serializeVariableText(''' |
| 6197 import 'a.dart'; | 6197 import 'a.dart'; |
| 6198 final v = (a = 1); | 6198 final v = (a = 1); |
| 6199 '''); | 6199 '''); |
| 6200 _assertUnlinkedConst(variable.constExpr, operators: [ | 6200 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6201 UnlinkedConstOperation.pushInt, | 6201 UnlinkedConstOperation.pushInt, |
| 6202 UnlinkedConstOperation.assignToRef, | 6202 UnlinkedConstOperation.assignToRef, |
| 6203 ], assignmentOperators: [ | 6203 ], assignmentOperators: [ |
| 6204 (UnlinkedExprAssignOperator.assign) | 6204 (UnlinkedExprAssignOperator.assign) |
| 6205 ], ints: [ | 6205 ], ints: [ |
| 6206 1, | 6206 1, |
| 6207 ], strings: [], referenceValidators: [ | 6207 ], strings: [], referenceValidators: [ |
| 6208 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', | 6208 (EntityRef r) => checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', |
| 6209 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 6209 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 6210 ]); | 6210 ]); |
| 6211 } | 6211 } |
| 6212 | 6212 |
| 6213 test_expr_assignToRef_topLevelVariable_imported_withPrefix() { | 6213 test_expr_assignToRef_topLevelVariable_imported_withPrefix() { |
| 6214 if (skipNonConstInitializers) { | 6214 if (skipNonConstInitializers) { |
| 6215 return; | 6215 return; |
| 6216 } | 6216 } |
| 6217 addNamedSource( | 6217 addNamedSource( |
| 6218 '/a.dart', | 6218 '/a.dart', |
| 6219 ''' | 6219 ''' |
| 6220 int a = 0; | 6220 int a = 0; |
| 6221 '''); | 6221 '''); |
| 6222 UnlinkedVariable variable = serializeVariableText(''' | 6222 UnlinkedVariable variable = serializeVariableText(''' |
| 6223 import 'a.dart' as p; | 6223 import 'a.dart' as p; |
| 6224 final v = (p.a = 1); | 6224 final v = (p.a = 1); |
| 6225 '''); | 6225 '''); |
| 6226 _assertUnlinkedConst(variable.constExpr, operators: [ | 6226 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6227 UnlinkedConstOperation.pushInt, | 6227 UnlinkedConstOperation.pushInt, |
| 6228 UnlinkedConstOperation.assignToRef, | 6228 UnlinkedConstOperation.assignToRef, |
| 6229 ], assignmentOperators: [ | 6229 ], assignmentOperators: [ |
| 6230 (UnlinkedExprAssignOperator.assign) | 6230 (UnlinkedExprAssignOperator.assign) |
| 6231 ], ints: [ | 6231 ], ints: [ |
| 6232 1, | 6232 1, |
| 6233 ], strings: [], referenceValidators: [ | 6233 ], strings: [], referenceValidators: [ |
| 6234 (EntityRef r) { | 6234 (EntityRef r) { |
| 6235 return checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', | 6235 return checkTypeRef(r, absUri('/a.dart'), 'a.dart', 'a', |
| 6236 expectedKind: ReferenceKind.topLevelPropertyAccessor, | 6236 expectedKind: ReferenceKind.topLevelPropertyAccessor, |
| 6237 expectedPrefix: 'p'); | 6237 expectedPrefix: 'p'); |
| 6238 } | 6238 } |
| 6239 ]); | 6239 ]); |
| 6240 } | 6240 } |
| 6241 | 6241 |
| 6242 test_expr_cascadeSection_assignToIndex() { |
| 6243 if (skipNonConstInitializers) { |
| 6244 return; |
| 6245 } |
| 6246 UnlinkedVariable variable = serializeVariableText(''' |
| 6247 class C { |
| 6248 List<int> items; |
| 6249 } |
| 6250 final C c = new C(); |
| 6251 final v = c.items..[1] = 2; |
| 6252 '''); |
| 6253 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6254 UnlinkedConstOperation.pushReference, |
| 6255 // ..[1] = 2 |
| 6256 UnlinkedConstOperation.cascadeSectionBegin, |
| 6257 UnlinkedConstOperation.pushInt, |
| 6258 UnlinkedConstOperation.pushInt, |
| 6259 UnlinkedConstOperation.assignToIndex, |
| 6260 // c |
| 6261 UnlinkedConstOperation.cascadeSectionEnd, |
| 6262 ], assignmentOperators: [ |
| 6263 UnlinkedExprAssignOperator.assign, |
| 6264 ], ints: [ |
| 6265 2, |
| 6266 1 |
| 6267 ], strings: [], referenceValidators: [ |
| 6268 (EntityRef r) => checkTypeRef(r, null, null, 'items', |
| 6269 expectedKind: ReferenceKind.unresolved, |
| 6270 prefixExpectations: [ |
| 6271 new _PrefixExpectation( |
| 6272 ReferenceKind.topLevelPropertyAccessor, 'c'), |
| 6273 ]) |
| 6274 ]); |
| 6275 } |
| 6276 |
| 6242 test_expr_cascadeSection_assignToProperty() { | 6277 test_expr_cascadeSection_assignToProperty() { |
| 6243 if (skipNonConstInitializers) { | 6278 if (skipNonConstInitializers) { |
| 6244 return; | 6279 return; |
| 6245 } | 6280 } |
| 6246 UnlinkedVariable variable = serializeVariableText(''' | 6281 UnlinkedVariable variable = serializeVariableText(''' |
| 6247 class C { | 6282 class C { |
| 6248 int f1 = 0; | 6283 int f1 = 0; |
| 6249 int f2 = 0; | 6284 int f2 = 0; |
| 6250 } | 6285 } |
| 6251 final v = new C()..f1 = 1..f2 += 2; | 6286 final v = new C()..f1 = 1..f2 += 2; |
| 6252 '''); | 6287 '''); |
| 6253 _assertUnlinkedConst(variable.constExpr, operators: [ | 6288 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6254 // new C() | 6289 // new C() |
| 6255 UnlinkedConstOperation.invokeConstructor, | 6290 UnlinkedConstOperation.invokeConstructor, |
| 6256 // ..f1 = 1 | 6291 // ..f1 = 1 |
| 6257 UnlinkedConstOperation.cascadeSectionBegin, | 6292 UnlinkedConstOperation.cascadeSectionBegin, |
| 6258 UnlinkedConstOperation.pushInt, | 6293 UnlinkedConstOperation.pushInt, |
| 6259 UnlinkedConstOperation.assignToProperty, | 6294 UnlinkedConstOperation.assignToProperty, |
| 6260 // C | 6295 // C |
| 6261 UnlinkedConstOperation.cascadeSectionEnd, | 6296 UnlinkedConstOperation.cascadeSectionEnd, |
| 6262 // ..f2 += 2 | 6297 // ..f2 += 2 |
| 6263 UnlinkedConstOperation.cascadeSectionBegin, | 6298 UnlinkedConstOperation.cascadeSectionBegin, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6274 2, // f2 += 2 | 6309 2, // f2 += 2 |
| 6275 ], strings: [ | 6310 ], strings: [ |
| 6276 'f1', | 6311 'f1', |
| 6277 'f2', | 6312 'f2', |
| 6278 ], referenceValidators: [ | 6313 ], referenceValidators: [ |
| 6279 (EntityRef r) => checkTypeRef(r, null, null, 'C', | 6314 (EntityRef r) => checkTypeRef(r, null, null, 'C', |
| 6280 expectedKind: ReferenceKind.classOrEnum) | 6315 expectedKind: ReferenceKind.classOrEnum) |
| 6281 ]); | 6316 ]); |
| 6282 } | 6317 } |
| 6283 | 6318 |
| 6284 test_expr_cascadeSection_assignToIndex() { | |
| 6285 if (skipNonConstInitializers) { | |
| 6286 return; | |
| 6287 } | |
| 6288 UnlinkedVariable variable = serializeVariableText(''' | |
| 6289 class C { | |
| 6290 List<int> items; | |
| 6291 } | |
| 6292 final C c = new C(); | |
| 6293 final v = c.items..[1] = 2; | |
| 6294 '''); | |
| 6295 _assertUnlinkedConst(variable.constExpr, operators: [ | |
| 6296 UnlinkedConstOperation.pushReference, | |
| 6297 // ..[1] = 2 | |
| 6298 UnlinkedConstOperation.cascadeSectionBegin, | |
| 6299 UnlinkedConstOperation.pushInt, | |
| 6300 UnlinkedConstOperation.pushInt, | |
| 6301 UnlinkedConstOperation.assignToIndex, | |
| 6302 // c | |
| 6303 UnlinkedConstOperation.cascadeSectionEnd, | |
| 6304 ], assignmentOperators: [ | |
| 6305 UnlinkedExprAssignOperator.assign, | |
| 6306 ], ints: [ | |
| 6307 2, | |
| 6308 1 | |
| 6309 ], strings: [], referenceValidators: [ | |
| 6310 (EntityRef r) => checkTypeRef(r, null, null, 'items', | |
| 6311 expectedKind: ReferenceKind.unresolved, | |
| 6312 prefixExpectations: [ | |
| 6313 new _PrefixExpectation( | |
| 6314 ReferenceKind.topLevelPropertyAccessor, 'c'), | |
| 6315 ]) | |
| 6316 ]); | |
| 6317 } | |
| 6318 | |
| 6319 test_expr_cascadeSection_embedded() { | 6319 test_expr_cascadeSection_embedded() { |
| 6320 if (skipNonConstInitializers) { | 6320 if (skipNonConstInitializers) { |
| 6321 return; | 6321 return; |
| 6322 } | 6322 } |
| 6323 UnlinkedVariable variable = serializeVariableText(''' | 6323 UnlinkedVariable variable = serializeVariableText(''' |
| 6324 class A { | 6324 class A { |
| 6325 int fa1; | 6325 int fa1; |
| 6326 B b; | 6326 B b; |
| 6327 int fa2; | 6327 int fa2; |
| 6328 } | 6328 } |
| 6329 class B { | 6329 class B { |
| 6330 int fb; | 6330 int fb; |
| 6331 } | 6331 } |
| 6332 final v = new A() | 6332 final v = new A() |
| 6333 ..fa1 = 1 | 6333 ..fa1 = 1 |
| 6334 ..b = (new B()..fb = 2) | 6334 ..b = (new B()..fb = 2) |
| 6335 ..fa2 = 3; | 6335 ..fa2 = 3; |
| 6336 '''); | 6336 '''); |
| 6337 _assertUnlinkedConst(variable.constExpr, operators: [ | 6337 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6338 // new A() | 6338 // new A() |
| 6339 UnlinkedConstOperation.invokeConstructor, | 6339 UnlinkedConstOperation.invokeConstructor, |
| 6340 // ..fa1 = 1 | 6340 // ..fa1 = 1 |
| 6341 UnlinkedConstOperation.cascadeSectionBegin, | 6341 UnlinkedConstOperation.cascadeSectionBegin, |
| 6342 UnlinkedConstOperation.pushInt, | 6342 UnlinkedConstOperation.pushInt, |
| 6343 UnlinkedConstOperation.assignToProperty, | 6343 UnlinkedConstOperation.assignToProperty, |
| 6344 UnlinkedConstOperation.cascadeSectionEnd, | 6344 UnlinkedConstOperation.cascadeSectionEnd, |
| 6345 // ..b | 6345 // ..b |
| 6346 UnlinkedConstOperation.cascadeSectionBegin, | 6346 UnlinkedConstOperation.cascadeSectionBegin, |
| 6347 // new B() | 6347 // new B() |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6389 if (skipNonConstInitializers) { | 6389 if (skipNonConstInitializers) { |
| 6390 return; | 6390 return; |
| 6391 } | 6391 } |
| 6392 UnlinkedVariable variable = serializeVariableText(''' | 6392 UnlinkedVariable variable = serializeVariableText(''' |
| 6393 class A { | 6393 class A { |
| 6394 int m(int _) => 0; | 6394 int m(int _) => 0; |
| 6395 } | 6395 } |
| 6396 final A a = new A(); | 6396 final A a = new A(); |
| 6397 final v = a..m(5).abs()..m(6); | 6397 final v = a..m(5).abs()..m(6); |
| 6398 '''); | 6398 '''); |
| 6399 _assertUnlinkedConst(variable.constExpr, operators: [ | 6399 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6400 // a | 6400 // a |
| 6401 UnlinkedConstOperation.pushReference, | 6401 UnlinkedConstOperation.pushReference, |
| 6402 // ..m(5) | 6402 // ..m(5) |
| 6403 UnlinkedConstOperation.cascadeSectionBegin, | 6403 UnlinkedConstOperation.cascadeSectionBegin, |
| 6404 UnlinkedConstOperation.pushInt, | 6404 UnlinkedConstOperation.pushInt, |
| 6405 UnlinkedConstOperation.invokeMethod, | 6405 UnlinkedConstOperation.invokeMethod, |
| 6406 // ..abs() | 6406 // ..abs() |
| 6407 UnlinkedConstOperation.invokeMethod, | 6407 UnlinkedConstOperation.invokeMethod, |
| 6408 // a | 6408 // a |
| 6409 UnlinkedConstOperation.cascadeSectionEnd, | 6409 UnlinkedConstOperation.cascadeSectionEnd, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6430 test_expr_extractIndex_ofClassField() { | 6430 test_expr_extractIndex_ofClassField() { |
| 6431 if (skipNonConstInitializers) { | 6431 if (skipNonConstInitializers) { |
| 6432 return; | 6432 return; |
| 6433 } | 6433 } |
| 6434 UnlinkedVariable variable = serializeVariableText(''' | 6434 UnlinkedVariable variable = serializeVariableText(''' |
| 6435 class C { | 6435 class C { |
| 6436 List<int> get items => null; | 6436 List<int> get items => null; |
| 6437 } | 6437 } |
| 6438 final v = new C().items[5]; | 6438 final v = new C().items[5]; |
| 6439 '''); | 6439 '''); |
| 6440 _assertUnlinkedConst(variable.constExpr, operators: [ | 6440 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6441 UnlinkedConstOperation.invokeConstructor, | 6441 UnlinkedConstOperation.invokeConstructor, |
| 6442 UnlinkedConstOperation.extractProperty, | 6442 UnlinkedConstOperation.extractProperty, |
| 6443 UnlinkedConstOperation.pushInt, | 6443 UnlinkedConstOperation.pushInt, |
| 6444 UnlinkedConstOperation.extractIndex, | 6444 UnlinkedConstOperation.extractIndex, |
| 6445 ], ints: [ | 6445 ], ints: [ |
| 6446 0, | 6446 0, |
| 6447 0, | 6447 0, |
| 6448 5 | 6448 5 |
| 6449 ], strings: [ | 6449 ], strings: [ |
| 6450 'items' | 6450 'items' |
| 6451 ], referenceValidators: [ | 6451 ], referenceValidators: [ |
| 6452 (EntityRef r) => checkTypeRef(r, null, null, 'C', | 6452 (EntityRef r) => checkTypeRef(r, null, null, 'C', |
| 6453 expectedKind: ReferenceKind.classOrEnum) | 6453 expectedKind: ReferenceKind.classOrEnum) |
| 6454 ]); | 6454 ]); |
| 6455 } | 6455 } |
| 6456 | 6456 |
| 6457 test_expr_extractProperty_ofInvokeConstructor() { | 6457 test_expr_extractProperty_ofInvokeConstructor() { |
| 6458 if (skipNonConstInitializers) { | 6458 if (skipNonConstInitializers) { |
| 6459 return; | 6459 return; |
| 6460 } | 6460 } |
| 6461 UnlinkedVariable variable = serializeVariableText(''' | 6461 UnlinkedVariable variable = serializeVariableText(''' |
| 6462 class C { | 6462 class C { |
| 6463 int f = 0; | 6463 int f = 0; |
| 6464 } | 6464 } |
| 6465 final v = new C().f; | 6465 final v = new C().f; |
| 6466 '''); | 6466 '''); |
| 6467 _assertUnlinkedConst(variable.constExpr, operators: [ | 6467 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6468 UnlinkedConstOperation.invokeConstructor, | 6468 UnlinkedConstOperation.invokeConstructor, |
| 6469 UnlinkedConstOperation.extractProperty, | 6469 UnlinkedConstOperation.extractProperty, |
| 6470 ], ints: [ | 6470 ], ints: [ |
| 6471 0, | 6471 0, |
| 6472 0 | 6472 0 |
| 6473 ], strings: [ | 6473 ], strings: [ |
| 6474 'f' | 6474 'f' |
| 6475 ], referenceValidators: [ | 6475 ], referenceValidators: [ |
| 6476 (EntityRef r) => checkTypeRef(r, null, null, 'C', | 6476 (EntityRef r) => checkTypeRef(r, null, null, 'C', |
| 6477 expectedKind: ReferenceKind.classOrEnum) | 6477 expectedKind: ReferenceKind.classOrEnum) |
| 6478 ]); | 6478 ]); |
| 6479 } | 6479 } |
| 6480 | 6480 |
| 6481 test_expr_invokeMethod_instance() { | 6481 test_expr_invokeMethod_instance() { |
| 6482 if (skipNonConstInitializers) { | 6482 if (skipNonConstInitializers) { |
| 6483 return; | 6483 return; |
| 6484 } | 6484 } |
| 6485 UnlinkedVariable variable = serializeVariableText(''' | 6485 UnlinkedVariable variable = serializeVariableText(''' |
| 6486 class C { | 6486 class C { |
| 6487 int m(a, {b, c}) => 42; | 6487 int m(a, {b, c}) => 42; |
| 6488 } | 6488 } |
| 6489 final v = new C().m(1, b: 2, c: 3); | 6489 final v = new C().m(1, b: 2, c: 3); |
| 6490 '''); | 6490 '''); |
| 6491 _assertUnlinkedConst(variable.constExpr, operators: [ | 6491 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6492 UnlinkedConstOperation.invokeConstructor, | 6492 UnlinkedConstOperation.invokeConstructor, |
| 6493 UnlinkedConstOperation.pushInt, | 6493 UnlinkedConstOperation.pushInt, |
| 6494 UnlinkedConstOperation.pushInt, | 6494 UnlinkedConstOperation.pushInt, |
| 6495 UnlinkedConstOperation.pushInt, | 6495 UnlinkedConstOperation.pushInt, |
| 6496 UnlinkedConstOperation.invokeMethod, | 6496 UnlinkedConstOperation.invokeMethod, |
| 6497 ], ints: [ | 6497 ], ints: [ |
| 6498 0, | 6498 0, |
| 6499 0, | 6499 0, |
| 6500 1, | 6500 1, |
| 6501 2, | 6501 2, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6522 } | 6522 } |
| 6523 class B { | 6523 class B { |
| 6524 C c; | 6524 C c; |
| 6525 } | 6525 } |
| 6526 class C { | 6526 class C { |
| 6527 int m(int a, int b) => a + b; | 6527 int m(int a, int b) => a + b; |
| 6528 } | 6528 } |
| 6529 A a = new A(); | 6529 A a = new A(); |
| 6530 final v = a.b.c.m(10, 20); | 6530 final v = a.b.c.m(10, 20); |
| 6531 '''); | 6531 '''); |
| 6532 _assertUnlinkedConst(variable.constExpr, operators: [ | 6532 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6533 UnlinkedConstOperation.pushInt, | 6533 UnlinkedConstOperation.pushInt, |
| 6534 UnlinkedConstOperation.pushInt, | 6534 UnlinkedConstOperation.pushInt, |
| 6535 UnlinkedConstOperation.invokeMethodRef, | 6535 UnlinkedConstOperation.invokeMethodRef, |
| 6536 ], ints: [ | 6536 ], ints: [ |
| 6537 10, | 6537 10, |
| 6538 20, | 6538 20, |
| 6539 0, | 6539 0, |
| 6540 2 | 6540 2 |
| 6541 ], strings: [], referenceValidators: [ | 6541 ], strings: [], referenceValidators: [ |
| 6542 (EntityRef r) => checkTypeRef(r, null, null, 'm', | 6542 (EntityRef r) => checkTypeRef(r, null, null, 'm', |
| (...skipping 15 matching lines...) Expand all Loading... |
| 6558 '/a.dart', | 6558 '/a.dart', |
| 6559 ''' | 6559 ''' |
| 6560 class C { | 6560 class C { |
| 6561 static int m() => 42; | 6561 static int m() => 42; |
| 6562 } | 6562 } |
| 6563 '''); | 6563 '''); |
| 6564 UnlinkedVariable variable = serializeVariableText(''' | 6564 UnlinkedVariable variable = serializeVariableText(''' |
| 6565 import 'a.dart' as p; | 6565 import 'a.dart' as p; |
| 6566 final v = p.C.m(); | 6566 final v = p.C.m(); |
| 6567 '''); | 6567 '''); |
| 6568 _assertUnlinkedConst(variable.constExpr, operators: [ | 6568 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6569 UnlinkedConstOperation.invokeMethodRef, | 6569 UnlinkedConstOperation.invokeMethodRef, |
| 6570 ], ints: [ | 6570 ], ints: [ |
| 6571 0, | 6571 0, |
| 6572 0 | 6572 0 |
| 6573 ], strings: [], referenceValidators: [ | 6573 ], strings: [], referenceValidators: [ |
| 6574 (EntityRef r) => checkTypeRef(r, null, null, 'm', | 6574 (EntityRef r) => checkTypeRef(r, null, null, 'm', |
| 6575 expectedKind: ReferenceKind.method, | 6575 expectedKind: ReferenceKind.method, |
| 6576 prefixExpectations: [ | 6576 prefixExpectations: [ |
| 6577 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C', | 6577 new _PrefixExpectation(ReferenceKind.classOrEnum, 'C', |
| 6578 absoluteUri: absUri('/a.dart'), relativeUri: 'a.dart'), | 6578 absoluteUri: absUri('/a.dart'), relativeUri: 'a.dart'), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6622 operators: [UnlinkedConstOperation.pushInt], ints: [0]); | 6622 operators: [UnlinkedConstOperation.pushInt], ints: [0]); |
| 6623 } | 6623 } |
| 6624 | 6624 |
| 6625 test_field_final_notConstExpr() { | 6625 test_field_final_notConstExpr() { |
| 6626 UnlinkedVariable variable = serializeClassText(r''' | 6626 UnlinkedVariable variable = serializeClassText(r''' |
| 6627 class C { | 6627 class C { |
| 6628 final int f = 1 + m(); | 6628 final int f = 1 + m(); |
| 6629 static int m() => 42; | 6629 static int m() => 42; |
| 6630 }''').fields[0]; | 6630 }''').fields[0]; |
| 6631 expect(variable.isFinal, isTrue); | 6631 expect(variable.isFinal, isTrue); |
| 6632 _assertUnlinkedConst(variable.constExpr, operators: [ | 6632 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 6633 UnlinkedConstOperation.pushInt, | 6633 UnlinkedConstOperation.pushInt, |
| 6634 UnlinkedConstOperation.invokeMethodRef, | 6634 UnlinkedConstOperation.invokeMethodRef, |
| 6635 UnlinkedConstOperation.add, | 6635 UnlinkedConstOperation.add, |
| 6636 ], ints: [ | 6636 ], ints: [ |
| 6637 1, | 6637 1, |
| 6638 0, | 6638 0, |
| 6639 0 | 6639 0 |
| 6640 ], strings: [], referenceValidators: [ | 6640 ], strings: [], referenceValidators: [ |
| 6641 (EntityRef r) => checkTypeRef(r, null, null, 'm', | 6641 (EntityRef r) => checkTypeRef(r, null, null, 'm', |
| 6642 expectedKind: ReferenceKind.method, | 6642 expectedKind: ReferenceKind.method, |
| (...skipping 2388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9031 */ | 9031 */ |
| 9032 void _assertAssignmentOperator( | 9032 void _assertAssignmentOperator( |
| 9033 String expr, UnlinkedExprAssignOperator expectedAssignOperator) { | 9033 String expr, UnlinkedExprAssignOperator expectedAssignOperator) { |
| 9034 if (skipNonConstInitializers) { | 9034 if (skipNonConstInitializers) { |
| 9035 return; | 9035 return; |
| 9036 } | 9036 } |
| 9037 UnlinkedVariable variable = serializeVariableText(''' | 9037 UnlinkedVariable variable = serializeVariableText(''' |
| 9038 int a = 0; | 9038 int a = 0; |
| 9039 final v = $expr; | 9039 final v = $expr; |
| 9040 '''); | 9040 '''); |
| 9041 _assertUnlinkedConst(variable.constExpr, operators: [ | 9041 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 9042 UnlinkedConstOperation.pushInt, | 9042 UnlinkedConstOperation.pushInt, |
| 9043 UnlinkedConstOperation.pushInt, | 9043 UnlinkedConstOperation.pushInt, |
| 9044 UnlinkedConstOperation.add, | 9044 UnlinkedConstOperation.add, |
| 9045 UnlinkedConstOperation.assignToRef, | 9045 UnlinkedConstOperation.assignToRef, |
| 9046 UnlinkedConstOperation.pushInt, | 9046 UnlinkedConstOperation.pushInt, |
| 9047 UnlinkedConstOperation.add, | 9047 UnlinkedConstOperation.add, |
| 9048 ], assignmentOperators: [ | 9048 ], assignmentOperators: [ |
| 9049 expectedAssignOperator | 9049 expectedAssignOperator |
| 9050 ], ints: [ | 9050 ], ints: [ |
| 9051 1, | 9051 1, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9092 */ | 9092 */ |
| 9093 void _assertRefPrefixPostfixIncrementDecrement( | 9093 void _assertRefPrefixPostfixIncrementDecrement( |
| 9094 String expr, UnlinkedExprAssignOperator expectedAssignmentOperator) { | 9094 String expr, UnlinkedExprAssignOperator expectedAssignmentOperator) { |
| 9095 if (skipNonConstInitializers) { | 9095 if (skipNonConstInitializers) { |
| 9096 return; | 9096 return; |
| 9097 } | 9097 } |
| 9098 UnlinkedVariable variable = serializeVariableText(''' | 9098 UnlinkedVariable variable = serializeVariableText(''' |
| 9099 int a = 0; | 9099 int a = 0; |
| 9100 final v = $expr; | 9100 final v = $expr; |
| 9101 '''); | 9101 '''); |
| 9102 _assertUnlinkedConst(variable.constExpr, operators: [ | 9102 _assertUnlinkedConst(variable.constExpr, isValidConst: false, operators: [ |
| 9103 UnlinkedConstOperation.assignToRef, | 9103 UnlinkedConstOperation.assignToRef, |
| 9104 UnlinkedConstOperation.pushInt, | 9104 UnlinkedConstOperation.pushInt, |
| 9105 UnlinkedConstOperation.add, | 9105 UnlinkedConstOperation.add, |
| 9106 ], assignmentOperators: [ | 9106 ], assignmentOperators: [ |
| 9107 expectedAssignmentOperator | 9107 expectedAssignmentOperator |
| 9108 ], ints: [ | 9108 ], ints: [ |
| 9109 2 | 9109 2 |
| 9110 ], strings: [], referenceValidators: [ | 9110 ], strings: [], referenceValidators: [ |
| 9111 (EntityRef r) => checkTypeRef(r, null, null, 'a', | 9111 (EntityRef r) => checkTypeRef(r, null, null, 'a', |
| 9112 expectedKind: ReferenceKind.topLevelPropertyAccessor) | 9112 expectedKind: ReferenceKind.topLevelPropertyAccessor) |
| 9113 ]); | 9113 ]); |
| 9114 } | 9114 } |
| 9115 | 9115 |
| 9116 /** | 9116 /** |
| 9117 * TODO(scheglov) rename "Const" to "Expr" everywhere | 9117 * TODO(scheglov) rename "Const" to "Expr" everywhere |
| 9118 */ | 9118 */ |
| 9119 void _assertUnlinkedConst(UnlinkedConst constExpr, | 9119 void _assertUnlinkedConst(UnlinkedConst constExpr, |
| 9120 {bool isInvalid: false, | 9120 {bool isValidConst: true, |
| 9121 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[], | 9121 List<UnlinkedConstOperation> operators: const <UnlinkedConstOperation>[], |
| 9122 List<UnlinkedExprAssignOperator> assignmentOperators: | 9122 List<UnlinkedExprAssignOperator> assignmentOperators: |
| 9123 const <UnlinkedExprAssignOperator>[], | 9123 const <UnlinkedExprAssignOperator>[], |
| 9124 List<int> ints: const <int>[], | 9124 List<int> ints: const <int>[], |
| 9125 List<double> doubles: const <double>[], | 9125 List<double> doubles: const <double>[], |
| 9126 List<String> strings: const <String>[], | 9126 List<String> strings: const <String>[], |
| 9127 List<_EntityRefValidator> referenceValidators: | 9127 List<_EntityRefValidator> referenceValidators: |
| 9128 const <_EntityRefValidator>[]}) { | 9128 const <_EntityRefValidator>[]}) { |
| 9129 expect(constExpr, isNotNull); | 9129 expect(constExpr, isNotNull); |
| 9130 expect(constExpr.isInvalid, isInvalid); | 9130 expect(constExpr.isValidConst, isValidConst); |
| 9131 expect(constExpr.operations, operators); | 9131 expect(constExpr.operations, operators); |
| 9132 expect(constExpr.ints, ints); | 9132 expect(constExpr.ints, ints); |
| 9133 expect(constExpr.doubles, doubles); | 9133 expect(constExpr.doubles, doubles); |
| 9134 expect(constExpr.strings, strings); | 9134 expect(constExpr.strings, strings); |
| 9135 expect(constExpr.assignmentOperators, assignmentOperators); | 9135 expect(constExpr.assignmentOperators, assignmentOperators); |
| 9136 expect(constExpr.references, hasLength(referenceValidators.length)); | 9136 expect(constExpr.references, hasLength(referenceValidators.length)); |
| 9137 for (int i = 0; i < referenceValidators.length; i++) { | 9137 for (int i = 0; i < referenceValidators.length; i++) { |
| 9138 referenceValidators[i](constExpr.references[i]); | 9138 referenceValidators[i](constExpr.references[i]); |
| 9139 } | 9139 } |
| 9140 } | 9140 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 9155 class _PrefixExpectation { | 9155 class _PrefixExpectation { |
| 9156 final ReferenceKind kind; | 9156 final ReferenceKind kind; |
| 9157 final String name; | 9157 final String name; |
| 9158 final String absoluteUri; | 9158 final String absoluteUri; |
| 9159 final String relativeUri; | 9159 final String relativeUri; |
| 9160 final int numTypeParameters; | 9160 final int numTypeParameters; |
| 9161 | 9161 |
| 9162 _PrefixExpectation(this.kind, this.name, | 9162 _PrefixExpectation(this.kind, this.name, |
| 9163 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 9163 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 9164 } | 9164 } |
| OLD | NEW |