| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 | 7 |
| 8 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import 'package:compiler/src/constants/expressions.dart'; | 10 import 'package:compiler/src/constants/expressions.dart'; |
| (...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 checkWarningOn(''' | 1248 checkWarningOn(''' |
| 1249 main() { new B().bar(); } | 1249 main() { new B().bar(); } |
| 1250 class A { | 1250 class A { |
| 1251 mname() {} | 1251 mname() {} |
| 1252 } | 1252 } |
| 1253 class B extends A { | 1253 class B extends A { |
| 1254 bar() { | 1254 bar() { |
| 1255 super.mname = () => 6; | 1255 super.mname = () => 6; |
| 1256 } | 1256 } |
| 1257 } | 1257 } |
| 1258 ''', [MessageKind.ASSIGNING_METHOD_IN_SUPER]); | 1258 ''', [MessageKind.ASSIGNING_METHOD_IN_SUPER, |
| 1259 // TODO(johnniwinther): Avoid duplicate warnings. |
| 1260 MessageKind.SETTER_NOT_FOUND]); |
| 1259 | 1261 |
| 1260 // But index operators should be OK | 1262 // But index operators should be OK |
| 1261 checkWarningOn(''' | 1263 checkWarningOn(''' |
| 1262 main() { new B().bar(); } | 1264 main() { new B().bar(); } |
| 1263 class B { | 1265 class B { |
| 1264 operator[]=(x, y) {} | 1266 operator[]=(x, y) {} |
| 1265 bar() { | 1267 bar() { |
| 1266 this[1] = 3; // This is OK | 1268 this[1] = 3; // This is OK |
| 1267 } | 1269 } |
| 1268 } | 1270 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 | 1326 |
| 1325 // ... and in super class: | 1327 // ... and in super class: |
| 1326 checkWarningOn(''' | 1328 checkWarningOn(''' |
| 1327 main() => new B().m(); | 1329 main() => new B().m(); |
| 1328 class A { | 1330 class A { |
| 1329 final x = 1; | 1331 final x = 1; |
| 1330 } | 1332 } |
| 1331 class B extends A { | 1333 class B extends A { |
| 1332 m() { super.x = 2; } | 1334 m() { super.x = 2; } |
| 1333 } | 1335 } |
| 1334 ''', [MessageKind.SETTER_NOT_FOUND_IN_SUPER]); | 1336 ''', [MessageKind.ASSIGNING_FINAL_FIELD_IN_SUPER, |
| 1337 // TODO(johnniwinther): Avoid duplicate warnings. |
| 1338 MessageKind.SETTER_NOT_FOUND]); |
| 1335 | 1339 |
| 1336 // But non-final fields are OK: | 1340 // But non-final fields are OK: |
| 1337 checkWarningOn(''' | 1341 checkWarningOn(''' |
| 1338 main() => new B().m(); | 1342 main() => new B().m(); |
| 1339 class A { | 1343 class A { |
| 1340 int x = 1; | 1344 int x = 1; |
| 1341 } | 1345 } |
| 1342 class B extends A { | 1346 class B extends A { |
| 1343 m() { super.x = 2; } | 1347 m() { super.x = 2; } |
| 1344 } | 1348 } |
| 1345 ''', []); | 1349 ''', []); |
| 1350 |
| 1351 // Check getter without setter. |
| 1352 checkWarningOn(''' |
| 1353 main() => new B().m(); |
| 1354 class A { |
| 1355 get x => 1; |
| 1356 } |
| 1357 class B extends A { |
| 1358 m() { super.x = 2; } |
| 1359 } |
| 1360 ''', [MessageKind.SETTER_NOT_FOUND_IN_SUPER, |
| 1361 // TODO(johnniwinther): Avoid duplicate warnings. |
| 1362 MessageKind.SETTER_NOT_FOUND]); |
| 1346 } | 1363 } |
| 1347 | 1364 |
| 1348 /// Helper to test that [script] produces all the given [warnings]. | 1365 /// Helper to test that [script] produces all the given [warnings]. |
| 1349 checkWarningOn(String script, List<MessageKind> warnings) { | 1366 checkWarningOn(String script, List<MessageKind> warnings) { |
| 1350 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2); | 1367 Expect.isTrue(warnings.length >= 0 && warnings.length <= 2); |
| 1351 asyncTest(() => compileScript(script).then((compiler) { | 1368 asyncTest(() => compileScript(script).then((compiler) { |
| 1352 Expect.equals(0, compiler.errors.length); | 1369 Expect.equals(0, compiler.errors.length, |
| 1353 Expect.equals(warnings.length, compiler.warnings.length); | 1370 'Unexpected errors in\n$script\n${compiler.errors}'); |
| 1371 Expect.equals(warnings.length, compiler.warnings.length, |
| 1372 'Unexpected warnings in\n$script\n' |
| 1373 'Expected:$warnings\nFound:${compiler.warnings}'); |
| 1354 for (int i = 0; i < warnings.length; i++) { | 1374 for (int i = 0; i < warnings.length; i++) { |
| 1355 Expect.equals(warnings[i], compiler.warnings[i].message.kind); | 1375 Expect.equals(warnings[i], compiler.warnings[i].message.kind); |
| 1356 } | 1376 } |
| 1357 })); | 1377 })); |
| 1358 } | 1378 } |
| 1359 | 1379 |
| 1360 testAwaitHint() { | 1380 testAwaitHint() { |
| 1361 check(String script, {String className, String functionName}) { | 1381 check(String script, {String className, String functionName}) { |
| 1362 var prefix = className == null | 1382 var prefix = className == null |
| 1363 ? "Cannot resolve 'await'" | 1383 ? "Cannot resolve 'await'" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1387 } | 1407 } |
| 1388 main() => A.m(); | 1408 main() => A.m(); |
| 1389 ''', functionName: 'm'); | 1409 ''', functionName: 'm'); |
| 1390 check(''' | 1410 check(''' |
| 1391 class A { | 1411 class A { |
| 1392 m() => () => await - 3; | 1412 m() => () => await - 3; |
| 1393 } | 1413 } |
| 1394 main() => new A().m(); | 1414 main() => new A().m(); |
| 1395 ''', className: 'A'); | 1415 ''', className: 'A'); |
| 1396 } | 1416 } |
| OLD | NEW |