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

Side by Side Diff: pkg/analyzer2dart/test/identifier_semantics_test.dart

Issue 702473002: Fix access semantics for foreach loops. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'package:unittest/unittest.dart'; 5 import 'package:unittest/unittest.dart';
6 import 'package:analyzer/file_system/memory_file_system.dart'; 6 import 'package:analyzer/file_system/memory_file_system.dart';
7 import 'mock_sdk.dart'; 7 import 'mock_sdk.dart';
8 import 'package:analyzer/src/generated/sdk.dart'; 8 import 'package:analyzer/src/generated/sdk.dart';
9 import 'package:analyzer/file_system/file_system.dart'; 9 import 'package:analyzer/file_system/file_system.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
(...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 Helper helper = new Helper(''' 1096 Helper helper = new Helper('''
1097 var x; 1097 var x;
1098 1098
1099 f() { 1099 f() {
1100 x = 1; 1100 x = 1;
1101 } 1101 }
1102 '''); 1102 ''');
1103 helper.checkStaticField('x', null, 'x', isWrite: true); 1103 helper.checkStaticField('x', null, 'x', isWrite: true);
1104 }); 1104 });
1105 1105
1106 test('Set variable defined at top level in foreach loop', () {
1107 Helper helper = new Helper('''
1108 var x;
1109
1110 f() {
1111 for (x in []) {}
1112 }
1113 ''');
1114 helper.checkStaticField('x', null, 'x', isWrite: true);
1115 });
1116
1106 test('Set variable defined at top level via prefix', () { 1117 test('Set variable defined at top level via prefix', () {
1107 Helper helper = new Helper(''' 1118 Helper helper = new Helper('''
1108 import 'lib.dart' as l; 1119 import 'lib.dart' as l;
1109 1120
1110 f() { 1121 f() {
1111 l.x = 1; 1122 l.x = 1;
1112 } 1123 }
1113 '''); 1124 ''');
1114 helper.addFile('/lib.dart', ''' 1125 helper.addFile('/lib.dart', '''
1115 library lib; 1126 library lib;
1116 1127
1117 var x; 1128 var x;
1118 '''); 1129 ''');
1119 helper.checkStaticField('l.x', null, 'x', isWrite: true); 1130 helper.checkStaticField('l.x', null, 'x', isWrite: true);
1120 }); 1131 });
1121 1132
1122 test('Set field defined statically in class from inside class', () { 1133 test('Set field defined statically in class from inside class', () {
1123 Helper helper = new Helper(''' 1134 Helper helper = new Helper('''
1124 class A { 1135 class A {
1125 static var x; 1136 static var x;
1126 1137
1127 f() { 1138 f() {
1128 x = 1; 1139 x = 1;
1129 } 1140 }
1130 } 1141 }
1131 '''); 1142 ''');
1132 helper.checkStaticField('x', 'A', 'x', isWrite: true); 1143 helper.checkStaticField('x', 'A', 'x', isWrite: true);
1133 }); 1144 });
1134 1145
1146 test('Set field defined statically in class from inside class in foreach' +
1147 ' loop', () {
1148 Helper helper = new Helper('''
1149 class A {
1150 static var x;
1151
1152 f() {
1153 for (x in []) {}
1154 }
1155 }
1156 ''');
1157 helper.checkStaticField('x', 'A', 'x', isWrite: true);
1158 });
1159
1135 test('Set field defined statically in class from outside class', () { 1160 test('Set field defined statically in class from outside class', () {
1136 Helper helper = new Helper(''' 1161 Helper helper = new Helper('''
1137 class A { 1162 class A {
1138 static var x; 1163 static var x;
1139 } 1164 }
1140 1165
1141 f() { 1166 f() {
1142 A.x = 1; 1167 A.x = 1;
1143 } 1168 }
1144 '''); 1169 ''');
(...skipping 26 matching lines...) Expand all
1171 var x; 1196 var x;
1172 1197
1173 f() { 1198 f() {
1174 x = 1; 1199 x = 1;
1175 } 1200 }
1176 } 1201 }
1177 '''); 1202 ''');
1178 helper.checkDynamic('x', null, 'x', isWrite: true); 1203 helper.checkDynamic('x', null, 'x', isWrite: true);
1179 }); 1204 });
1180 1205
1206 test('Set field defined dynamically in class from inside class in foreach' +
1207 ' loop', () {
1208 Helper helper = new Helper('''
1209 class A {
1210 var x;
1211
1212 f() {
1213 for (x in []) {}
1214 }
1215 }
1216 ''');
1217 helper.checkDynamic('x', null, 'x', isWrite: true);
1218 });
1219
1181 test( 1220 test(
1182 'Set field defined dynamically in class from outside class via typed var', 1221 'Set field defined dynamically in class from outside class via typed var',
1183 () { 1222 () {
1184 Helper helper = new Helper(''' 1223 Helper helper = new Helper('''
1185 class A { 1224 class A {
1186 var x; 1225 var x;
1187 } 1226 }
1188 1227
1189 f(A a) { 1228 f(A a) {
1190 a.x = 1; 1229 a.x = 1;
(...skipping 22 matching lines...) Expand all
1213 test('Set variable defined locally', () { 1252 test('Set variable defined locally', () {
1214 Helper helper = new Helper(''' 1253 Helper helper = new Helper('''
1215 f() { 1254 f() {
1216 var x; 1255 var x;
1217 x = 1; 1256 x = 1;
1218 } 1257 }
1219 '''); 1258 ''');
1220 helper.checkLocalVariable('x', 'x', isWrite: true); 1259 helper.checkLocalVariable('x', 'x', isWrite: true);
1221 }); 1260 });
1222 1261
1262 test('Set variable defined locally in foreach loop', () {
1263 Helper helper = new Helper('''
1264 f() {
1265 var x;
1266 for (x in []) {}
1267 }
1268 ''');
1269 helper.checkLocalVariable('x', 'x', isWrite: true);
1270 });
1271
1223 test('Set variable defined in parameter', () { 1272 test('Set variable defined in parameter', () {
1224 Helper helper = new Helper(''' 1273 Helper helper = new Helper('''
1225 f(x) { 1274 f(x) {
1226 x = 1; 1275 x = 1;
1227 } 1276 }
1228 '''); 1277 ''');
1229 helper.checkParameter('x', 'x', isWrite: true); 1278 helper.checkParameter('x', 'x', isWrite: true);
1230 }); 1279 });
1231 1280
1281 test('Set variable defined in parameter in foreach loop', () {
1282 Helper helper = new Helper('''
1283 f(x) {
1284 for (x in []) {}
1285 }
1286 ''');
1287 helper.checkParameter('x', 'x', isWrite: true);
1288 });
1289
1232 test('Set accessor defined at top level', () { 1290 test('Set accessor defined at top level', () {
1233 Helper helper = new Helper(''' 1291 Helper helper = new Helper('''
1234 set x(value) {}; 1292 set x(value) {};
1235 1293
1236 f() { 1294 f() {
1237 x = 1; 1295 x = 1;
1238 } 1296 }
1239 '''); 1297 ''');
1240 helper.checkStaticProperty('x', null, 'x', true, isWrite: true); 1298 helper.checkStaticProperty('x', null, 'x', true, isWrite: true);
1241 }); 1299 });
1242 1300
1301 test('Set accessor defined at top level in foreach loop', () {
1302 Helper helper = new Helper('''
1303 set x(value) {};
1304
1305 f() {
1306 for (x in []) {}
1307 }
1308 ''');
1309 helper.checkStaticProperty('x', null, 'x', true, isWrite: true);
1310 });
1311
1243 test('Set accessor defined at top level via prefix', () { 1312 test('Set accessor defined at top level via prefix', () {
1244 Helper helper = new Helper(''' 1313 Helper helper = new Helper('''
1245 import 'lib.dart' as l; 1314 import 'lib.dart' as l;
1246 1315
1247 f() { 1316 f() {
1248 l.x = 1; 1317 l.x = 1;
1249 } 1318 }
1250 '''); 1319 ''');
1251 helper.addFile('/lib.dart', ''' 1320 helper.addFile('/lib.dart', '''
1252 library lib; 1321 library lib;
1253 1322
1254 set x(value) {}; 1323 set x(value) {};
1255 '''); 1324 ''');
1256 helper.checkStaticProperty('l.x', null, 'x', true, isWrite: true); 1325 helper.checkStaticProperty('l.x', null, 'x', true, isWrite: true);
1257 }); 1326 });
1258 1327
1259 test('Set accessor defined statically in class from inside class', () { 1328 test('Set accessor defined statically in class from inside class', () {
1260 Helper helper = new Helper(''' 1329 Helper helper = new Helper('''
1261 class A { 1330 class A {
1262 static set x(value) {} 1331 static set x(value) {}
1263 1332
1264 f() { 1333 f() {
1265 x = 1; 1334 x = 1;
1266 } 1335 }
1267 } 1336 }
1268 '''); 1337 ''');
1269 helper.checkStaticProperty('x', 'A', 'x', true, isWrite: true); 1338 helper.checkStaticProperty('x', 'A', 'x', true, isWrite: true);
1270 }); 1339 });
1271 1340
1341 test('Set accessor defined statically in class from inside class in' +
1342 ' foreach loop', () {
1343 Helper helper = new Helper('''
1344 class A {
1345 static set x(value) {}
1346
1347 f() {
1348 for (x in []) {}
1349 }
1350 }
1351 ''');
1352 helper.checkStaticProperty('x', 'A', 'x', true, isWrite: true);
1353 });
1354
1272 test('Set accessor defined statically in class from outside class', () { 1355 test('Set accessor defined statically in class from outside class', () {
1273 Helper helper = new Helper(''' 1356 Helper helper = new Helper('''
1274 class A { 1357 class A {
1275 static set x(value) {} 1358 static set x(value) {}
1276 } 1359 }
1277 1360
1278 f() { 1361 f() {
1279 A.x = 1; 1362 A.x = 1;
1280 } 1363 }
1281 '''); 1364 ''');
(...skipping 26 matching lines...) Expand all
1308 set x(value) {} 1391 set x(value) {}
1309 1392
1310 f() { 1393 f() {
1311 x = 1; 1394 x = 1;
1312 } 1395 }
1313 } 1396 }
1314 '''); 1397 ''');
1315 helper.checkDynamic('x', null, 'x', isWrite: true); 1398 helper.checkDynamic('x', null, 'x', isWrite: true);
1316 }); 1399 });
1317 1400
1401 test('Set accessor defined dynamically in class from inside class in' +
1402 ' foreach loop', () {
1403 Helper helper = new Helper('''
1404 class A {
1405 set x(value) {}
1406
1407 f() {
1408 for (x in []) {}
1409 }
1410 }
1411 ''');
1412 helper.checkDynamic('x', null, 'x', isWrite: true);
1413 });
1414
1318 test( 1415 test(
1319 'Set accessor defined dynamically in class from outside class via typed va r', 1416 'Set accessor defined dynamically in class from outside class via typed va r',
1320 () { 1417 () {
1321 Helper helper = new Helper(''' 1418 Helper helper = new Helper('''
1322 class A { 1419 class A {
1323 set x(value) {} 1420 set x(value) {}
1324 } 1421 }
1325 1422
1326 f(A a) { 1423 f(A a) {
1327 a.x = 1; 1424 a.x = 1;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 1470
1374 test('Set accessor undefined at top level', () { 1471 test('Set accessor undefined at top level', () {
1375 Helper helper = new Helper(''' 1472 Helper helper = new Helper('''
1376 f() { 1473 f() {
1377 x = 1; 1474 x = 1;
1378 } 1475 }
1379 '''); 1476 ''');
1380 helper.checkDynamic('x', null, 'x', isWrite: true); 1477 helper.checkDynamic('x', null, 'x', isWrite: true);
1381 }); 1478 });
1382 1479
1480 test('Set accessor undefined at top level in foreach loop', () {
1481 Helper helper = new Helper('''
1482 f() {
1483 for (x in []) {}
1484 }
1485 ''');
1486 helper.checkDynamic('x', null, 'x', isWrite: true);
1487 });
1488
1383 test('Set accessor undefined at top level via prefix', () { 1489 test('Set accessor undefined at top level via prefix', () {
1384 Helper helper = new Helper(''' 1490 Helper helper = new Helper('''
1385 import 'lib.dart' as l; 1491 import 'lib.dart' as l;
1386 1492
1387 f() { 1493 f() {
1388 l.x = 1; 1494 l.x = 1;
1389 } 1495 }
1390 '''); 1496 ''');
1391 helper.addFile('/lib.dart', ''' 1497 helper.addFile('/lib.dart', '''
1392 library lib; 1498 library lib;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1427 Helper helper = new Helper(''' 1533 Helper helper = new Helper('''
1428 class A { 1534 class A {
1429 f() { 1535 f() {
1430 x = 1; 1536 x = 1;
1431 } 1537 }
1432 } 1538 }
1433 '''); 1539 ''');
1434 helper.checkDynamic('x', null, 'x', isWrite: true); 1540 helper.checkDynamic('x', null, 'x', isWrite: true);
1435 }); 1541 });
1436 1542
1543 test('Set accessor undefined dynamically in class from inside class in' +
1544 ' foreach loop', () {
1545 Helper helper = new Helper('''
1546 class A {
1547 f() {
1548 for (x in []) {}
1549 }
1550 }
1551 ''');
1552 helper.checkDynamic('x', null, 'x', isWrite: true);
1553 });
1554
1437 test( 1555 test(
1438 'Set accessor undefined dynamically in class from outside class via typed var', 1556 'Set accessor undefined dynamically in class from outside class via typed var',
1439 () { 1557 () {
1440 Helper helper = new Helper(''' 1558 Helper helper = new Helper('''
1441 class A {} 1559 class A {}
1442 1560
1443 f(A a) { 1561 f(A a) {
1444 a.x = 1; 1562 a.x = 1;
1445 } 1563 }
1446 '''); 1564 ''');
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 } 2251 }
2134 2252
2135 @override 2253 @override
2136 visitSimpleIdentifier(SimpleIdentifier node) { 2254 visitSimpleIdentifier(SimpleIdentifier node) {
2137 AccessSemantics semantics = node.accept(ACCESS_SEMANTICS_VISITOR); 2255 AccessSemantics semantics = node.accept(ACCESS_SEMANTICS_VISITOR);
2138 if (semantics != null) { 2256 if (semantics != null) {
2139 onAccess(node, semantics); 2257 onAccess(node, semantics);
2140 } 2258 }
2141 } 2259 }
2142 } 2260 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/ast.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698